tags:

views:

96

answers:

3

Good morning, everyone.

Can someone please let me know the correct way to select an element type with a given attribute? In my particular case I'm trying to access a label with a an attribute of "for" that has a value of "P500_CB_TRANSFERUNIVERSITY".

I would have though the propery jQuery syntax would be something like
$('label [for=P500_CB_TRANSFERUNIVERSITY]') but that doesn't seem to work.

Thanks in advance, Matt

A: 

Looks like you are missing quotes around the attribute value. This should work fine:

$("label[for='P500_CB_TRANSFERUNIVERSITY']")
Mark
Quotes aren't needed because there's no spaces.
Sonny Boy
The inner quotes aren't the problem. The issue is the space between label and [.
Andrew
ahh didn't even notice the space. I always use quotes, must be out of habit so I thought it was the proper way to do it
Mark
+1  A: 

Try:

$('label[for=P500_CB_TRANSFERUNIVERSITY]')

which is exactly the same, just with the space removed.

Andrew
+2  A: 

Just take the space out and it should work:

$("label[for=P500_CB_TRANSFERUNIVERSITY]")
Greg
Nice catch, I didn't even notice it.
ChaosPandion