Why val() is not returning the value of <button value="value">?

I read that val() returns value of input element but here in my code it is not working.
What

<script>
$(document).ready(function(){
    var a = $("button").val();
    alert(a)
});
</script>
<button value="text"/>

Thanks in advance

>Solution :

Use button element and call .html()

<button>value1</button>

or use input element and call .val()

<input type="button" value="value1"/>

Then access them as

// jquery
<script>
$(document).ready(function(){
    var btn = $("button").html();
    var inp = $("input").va();
    alert('button: '+btn)
    alert('input: '+inp)
});
</script>

//html
<input type="button" value="value1"/>
<button>value1</button>

Leave a Reply