Hacking the MvcHtmlString

I have an unknown problem setting the default value in a SelectList, when using DropDownListFor() with Razor. SO I was thinking about using jQuery to insert that attribute: Selected='true' at least until I found the source of my problem.

I know the name of the text for the list item, "Name of first pet?"

What's the jQuery I need to grab the list item and insert a new attribute? Or, if you have a better idea to set the default value of a drop down, I'd love to hear it.

Thanks!
newbiewebSr. Software EngineerAsked:
Who is Participating?
 
effxConnect With a Mentor Commented:
$("select[name=yourlist]").append("<option>newitem</option>");
0
 
effxConnect With a Mentor Commented:
$("select[name=yourlist]").val("yourvalue");
0
 
newbiewebSr. Software EngineerAuthor Commented:
Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.