Code:
$(".drpdwn")[0].options.value = "1"
I need to change this value to "string"
So, I coded as,
$(".drpdwn")[0].options.value = "string"
But, the value becomes as ""
in quickwatch.
How to apply string value?
Code:
$(".drpdwn")[0].options.value = "1"
I need to change this value to "string"
So, I coded as,
$(".drpdwn")[0].options.value = "string"
But, the value becomes as ""
in quickwatch.
How to apply string value?
$('.drpdwn').val('string');
See the docs.
Edit:
As there is some confusion about this. $('.drpdwn')
is a jQuery object representing all elements with the drpdwn
class. This jQuery object has a val
method. If you select only one of the matched objects using $('.drpdwn')[0]
you get a DOM object (pretty much what you would get if you did document.getElementsByClassName('drpdwn')[0]
). This obviously has no val
method.
The better way of going around this, is making $('.drpdwn')
more precise, so that it only matches the element you want to change. The easiest way is by giving your element an id (ala <div id="myElement" class="drpdwn"></div>
) and selecting it with $('#myElement')
. The other way would be by using the value
property of the DOM object, like $('.drpdwn')[0].value
. This will however break as soon as you insert an other element with that class before the element you want to change.
using jQuery,
$(".drpdwn").val("string");
I think you're trying in JS. if so
document.getElementsByClassName("drpdwn").value="string";