DBJDBJ wrote:
> Maybe one can do this, as jQ author writes: "weird characters in its
> ID" . But this is a bad programming practice.
> Why would anyone do that?  When was the last time (if ever) you did
> that? If Matt Brenna want to do some indexing of some elements there
> are much safer,scaleable and robust ways to do this. Like using data()
> method etc ... Or in a spirit of HTML5, and to be 'future proof' one
> might do something like this :
>
> <input type="text" data-no="1" data-tag="firstname" />
> <input type="text" data-no="2" data-tag="firstname" />
>
> And before HTML5 browsers become mainstream Matt can use jQuery :
>
> $("input[data-no=1][data-tag=firstname]")
>
> This in my mind is the right kind of advice to give to (jQ) beginers
> (no offence Matt ;o). But again I have to remind you: this forum is
> not a place for that.
>
> Also I could not make this work :
>
> // function from Frequently_Asked_Questions
> function jq(myid) { return '#'+myid.replace(/:/g,"\\:").replace(/\./
> g,"\\.");}
>
> $(document.body).append("<div id='A[2]' ></div>") ;
> $(jq("A[2]")).length
> /*
> 0
> */
>
> It must be something obvious but I do not see it ?
>
> -- DBJ
>   
The function doesn't have any code to escape the []'s
Try this one:

function jq(myid) { return '#'+myid.replace(/([:\.\[\]])/g,"\\$1");}


As for use of the [] in id's, I do not believe this has anything to do 
with making id's indexable or whatever. At the least not for any of my 
reasons to do it.
In the context of programming on the server side I find this perfectly 
reasonable:
HTML::labeledInput($label, $name, $value=""); -> <label 
for="{$name}">{$label}</label><input type="text" name="{$name}" 
id="{$name}" value="{$value}" />
HTML::labeledInput("FooBar", "foobar[1]"); -> <label 
for="foobar[1]">FooBar</label><input type="text" name="foobar[1]" 
id="foobar[1]" value="" />

name and id serve two different purposes. Name is the only one you can 
use to submit an input's data. And id is the only one that works for 
making labels work. But I see little value in forcing extra unnecessary 
inputs, or rewriting id's in some messy way that makes it harder to do 
things client side. So I wouldn't doubt that there are html libaries 
that do this kind of thing.
>
> On Apr 16, 1:03 pm, "Richard D. Worth" <rdwo...@gmail.com> wrote:
>   
>> On Wed, Apr 15, 2009 at 12:23 PM, Daniel Friesen
>> <nadir.seen.f...@gmail.com>wrote:
>>
>>
>>
>>     
>>> Fact is that jQuery does support using characters like :[] by escaping
>>> them with a \ and that should be noted when someone does not know.
>>>       
>> It's noted here:
>>
>> http://docs.jquery.com/Frequently_Asked_Questions#How_do_I_select_an_...
>>
>> - Richard
>>     
~Daniel Friesen (Dantman, Nadir-Seen-Fire) [http://nadir-seen-fire.com]
-Nadir-Point & Wiki-Tools (http://nadir-point.com) (http://wiki-tools.com)
-MonkeyScript (http://monkeyscript.org)
-Animepedia (http://anime.wikia.com)
-Narutopedia (http://naruto.wikia.com)
-Soul Eater Wiki (http://souleater.wikia.com)


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to jquery-dev@googlegroups.com
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to