Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
self.$el[0].options[0]
I get:
<option value="asd">asd</option> self.$el[0].options[0].attr("selected","selected")
is not a function.
How do I modify the asd in js? Is it because it's an html element?
$el[0].value="asd";
$el[0].selectedIndex=0
.getAttribute
.attr
Your selector gets the DOM node. So, any jquery method won't get applied on DOM element. Instead you make it a jquery object:
$(self.$el[0].options[0]).attr("selected","selected")
or you can use setAttribute() of DOM method:
setAttribute()
self.$el[0].options[0].setAttribute("selected","selected")
Add a comment
you can use js API:
document.getElementByTagNames['option'][0].setAtttribute('selected', 'selected')
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
$el[0].value="asd";will select the option - also$el[0].selectedIndex=0will select the first option.getAttributeinstead of.attr