Reputation: 11
can some one help me with code to get element by classname and also change the name
currently ive tried
$('selected').attr("name", 'blah blah');
and also
$('.selected').attr("name", 'blah blah');
noneof these work thanks
Upvotes: 0
Views: 483
Reputation: 75427
$('.classname')
should work for finding your elements by class name (try by checking .length
).attr("name", "foo")
should definitely work.Care to share some HTML code and matching JavaScript?
EDIT:
Given your sample code, and assuming you're using ASP.NET MVC's Html
helper.
HtmlHelper.DropDownList
, there's a period in it ("cat.parent_id
")HtmlHelper.DropDownList
supports the way you're trying to pass a class to each <option>
element (but you can verify by viewing the page's source).If what you're trying to do is change the text in the currently-selected option, and given:
<%= Html.DropDownList('my_ddlist', someEnumerable); %>
You can try to use jQuery's ":selected
" pseudo-selector instead, and change the option text with .text()
:
$('select#my_ddlist option:selected').text("foo");
If you're trying to do something else, can you explain what?
Upvotes: 2