Hi Karl: That clears it up completely. Thanks!
Charlie On Thu, Sep 17, 2009 at 10:43 AM, Karl Swedberg <k...@englishrules.com>wrote: > Hey Charlie, > It all comes down to the way the string is parsed. The Sizzle selector > engine uses a Regular Expression to detect whether an attribute selector is > being used: > > ATTR: > /\[\s*((?:[\w\u00c0-\uFFFF_-]|\\.)+)\s*(?:(\S?=)\s*(['"]*)(.*?)\3|)\s*\]/, > > The parts of the regex that deal with quotation marks around the attribute > value are (['"]*) and \3. The part that actually captures the attribute > value is (.*?) > So, it allows for single, double, or no quotation marks around the > attribute value in the selector. > > Come to think of it, it also allows for multiple quotation marks. Strange, > but this would work, too: > $("input[name='''newsletter''']") > > It isn't really related to literal text vs. variable value. In order to > pass in a variable, you need to concatenate it: > > var foo = 'newsletter'; > $("input[name=" + foo + "]") > > Hope that helps explain. > > --Karl > > ____________ > Karl Swedberg > www.englishrules.com > www.learningjquery.com > > > > > On Sep 17, 2009, at 12:22 PM, Charlie Griefer wrote: > > Hi Karl: > > Hate to hijack the thread, but hopefully it's somewhat relevant to the > original post. > > When I suggested the single quotes around the value 'bar', I was going off > of what I saw in the docs at > http://docs.jquery.com/Selectors/attributeEquals#attributevalue > > And the code sample: > $("input[name='newsletter']").next().text(" is newsletter"); > > I still consider myself relatively new to jQuery, so could you clarify > about quoting the attribute value? Is it similar to terminating a line with > a semi-colon (e.g. optional in JS)? Or is it literal text vs variable value > (assuming -bar- here is a variable)? > > Thanks! > Charlie > > On Thu, Sep 17, 2009 at 9:06 AM, Karl Swedberg <k...@englishrules.com>wrote: > >> >> On Sep 17, 2009, at 5:13 AM, Charlie Griefer wrote: >> >> Pretty sure you need single quotes around bar. >> >> alert($("input[name='bar']").val()); >> >> >> No. The single quotes are unnecessary. >> >> On Thu, Sep 17, 2009 at 1:27 AM, pritisolanki <pritiatw...@gmail.com> >> wrote: >> >>> >>> Thanks Ralph. >>> >>> I tried following >>> >>> alert($("input[name=bar]").val()); >>> >>> and rather then showing it's value it alert undefined ??? why? >>> >> >> Where are you including your script tag? If it's in the <head>, are you >> wrapping your alert() in $(document).ready? Are you sure you have an input >> with name="bar"? >> >> Try this: >> >> $(document).ready(function() { >> alert( $("input[name=bar]").val() ); >> }); >> >> >> --Karl >> >> ____________ >> Karl Swedberg >> www.englishrules.com >> www.learningjquery.com >> >> >> > > > -- > I have failed as much as I have succeeded. But I love my life. I love my > wife. And I wish you my kind of success. > > > -- Charlie Griefer http://charlie.griefer.com/ I have failed as much as I have succeeded. But I love my life. I love my wife. And I wish you my kind of success.