tags:

views:

42

answers:

1

Hello

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

+1  A: 
  • $('.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.

  1. You may be passing a bad name to HtmlHelper.DropDownList, there's a period in it ("cat.parent_id")
  2. I'm not sure 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?

orip
thats the html <tr><td> <%=Html.Label("Category")%></td><td> <%= Html.DropDownList("cat.parent_id", (IEnumerable<SelectListItem>)ViewData.Model.AllCategoriesList, "-please select item-", new { className = "unselected" })%> </td>
tom
i cant paste the script not enough characters sorry
tom
tom, you can edit your original question and add the code. So you are trying to get at a `<select>` element? It's not clear based on the question.
artlung