I want to add a single word attribute to an object.
Should be: <option selected>aaa</option>
Not: <option selected="selected">aaa</option>
Using jQuery or javascript.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
<option selected>is just HTML shorthand for<option selected="selected">. When you view a webpage, your browser will convert the HTML into a DOM (which doesn’t care which syntax was used to create it). You can then manipulate the DOM (this is important, you are not manipulating the original HTML, just what the browser has parsed it into).If you ever serialise the DOM back to HTML then you might get
<option selected>or<option selected="selected">depending on how the serializer was implemented. You will probably do this by asking the browser to provide theinnerHTMLof an element, in which case which you get is determined by the browser authors and you have no control over it.If it is important to express the selected attribute using the shorthand form, then you will have to use an alternative seraliser that gives you that control. I’m not aware of any, so you might have to write something from scratch.