passing a variable through an attribute filter
|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
passing a variable through an attribute filterHi Guys,
This is my very first post! so please be kind.... :) Ok, i am very novice to jQuery. But what i am trying to do is use the jQuery attribute selector to select an input with a specific name. I can select an input of name type fine by doing the folowing: $("input[name='name']").do something... But, can i pass a variable into that filter? to search for a variable? So if i had a variable called 'field_name' containing the text: 'email', can i do something like this: $("input[name='(field_name)']").do something... So that it in this caseit would find an input with the name 'email' Sorry if this is a doofus question, just can't find any examples of this anywhere thanks for your help guys, cheers Craig |
|
|
Re: passing a variable through an attribute filterYes, you can do this!!!
Sorry for my poor english but I hope help you! $("input[name='txtName']").css('background-color','#F00'); And this way too. var field_property = "txtName"; $("input[name='+field_property+']").css('background-color','#F00'); 2009/11/3 barbercraig <craigbarber75@...>
-- Abraços...... Marcel Araujo System Analyst Developer Java/PHP/RIA Linux User #490101 |
|
|
Re: passing a variable through an attribute filterLet's see :
$("input[name='name']") So, what is that exactly ?
Well, let's try something a little bit more acrobatic : var field_name = "name"; $("input[name='" + field_name + "']") Awesome. Hope it helps. Michel Belleville 2009/11/3 barbercraig <craigbarber75@...>
|
|
|
Re: passing a variable through an attribute filterCraig... just keep one major thought in regards to selectors.... *
it's just a string * and whether you hard code it in there or build it up like the post above demonstrates, in the end you are just passing a string to the selector engine...... |
| Free embeddable forum powered by Nabble | Forum Help |