[jQuery] Re: Selector Containing Variable

2008-01-30 Thread [EMAIL PROTECTED]

You have to escape the first set of double quotes -- leave the single
quotes there.

var tabTest = "billy";
$(".orderInfo[id='" + tabTest + "'"];

On Jan 30, 7:24 am, studiobl <[EMAIL PROTECTED]> wrote:
> I'm having trouble with a jQuery selector that contains a variable.
> I'm trying to target an element that has a class of "orderInfo" and an
> id of "billy"
>
> So, I set a variable:
>
> var tabText = "billy";
>
> ...and it works if I use the string:
>
> $(".orderInfo[id='billy'"];
>
> ...but not the variable:
>
> $(".orderInfo[id=tabTest"];
>
> ...but of course I need it to work with a variable {insert appropriate
> emoticon here}


[jQuery] Re: Selector Containing Variable

2008-01-30 Thread FrenchiINLA

you can try $('#' + tabtext) since the id is unic you don't need the
class.

On Jan 30, 7:24 am, studiobl <[EMAIL PROTECTED]> wrote:
> I'm having trouble with a jQuery selector that contains a variable.
> I'm trying to target an element that has a class of "orderInfo" and an
> id of "billy"
>
> So, I set a variable:
>
> var tabText = "billy";
>
> ...and it works if I use the string:
>
> $(".orderInfo[id='billy'"];
>
> ...but not the variable:
>
> $(".orderInfo[id=tabTest"];
>
> ...but of course I need it to work with a variable {insert appropriate
> emoticon here}


[jQuery] Re: Selector Containing Variable

2008-01-30 Thread Bohdan Ganicky


Hi,

as Karl said...and you could also make things a little bit shorter by using
multiple selector:

var tabText = 'billy';
$('.orderInfo#'+tabText];

--
Bohdan
-- 
View this message in context: 
http://www.nabble.com/Selector-Containing-Variable-tp15188162s27240p15194100.html
Sent from the jQuery General Discussion mailing list archive at Nabble.com.



[jQuery] Re: Selector Containing Variable

2008-01-30 Thread Karl Swedberg




On Jan 30, 2008, at 10:24 AM, studiobl wrote:



I'm having trouble with a jQuery selector that contains a variable.
I'm trying to target an element that has a class of "orderInfo" and an
id of "billy"

So, I set a variable:

var tabText = "billy";

...and it works if I use the string:

$(".orderInfo[id='billy'"];

...but not the variable:

$(".orderInfo[id=tabTest"];


...but of course I need it to work with a variable {insert appropriate
emoticon here}


Hi there,

The trick here is to concatenate the variable with the selector  
string. Something like this should work:


$(".orderInfo[id=" + tabTest + "]");


--Karl
_
Karl Swedberg
www.englishrules.com
www.learningjquery.com