I want to get the name of the two <p> elements in my html file using id after the button is clicked. but in my code, when I clicked the button, i it only outputs "print". How can I do this?
This is my HTML code:
<p id="name" name="print">hey</p>
<p id="name" name="this">hey</p>
<button id="btn11">test11</button>
This is my javascript code:
$("#btn11").click(function(){
alert($("#name").attr("name"));
});
use class instead of ID and
<p class= "name" name = "print">hey</p>
<p class= "name" name = "this">hey/p>
<button id="btn11">test11</button>
$("#btn11").click(function(){
$('.name').each(function () {
alert( $(this).attr('name'));
});
});
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