I want to get HTML element by it's value using Javascript.
I thought that there is function like getElementByValue() but there isn't.
How I can do it?
I don't know what exactly you want to achieve, but following are the ways you can use to get value of an element.
Select element using id and then get value of it. This works cross browser.
var my_id = document.getElementById("my_id"); var my_value = my_id.value;
Select element using class name (this works on all modern browser but not on ie8 and below)
var my_class = document.getElementsByClassName("my_class"); var count = my_class.length; for(var i = 0; i < count; i++){ my_class[i].value; }
3.Select element using tag name
var my_tag = document.getElementsByTagName("my_tag");
var count = my_tag.length;
for(var i = 0; i < count; i++){
my_tag[i].value;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With