I need help please If the next code.
I have two lines of
Now I want my code in JQ when the user clicks One of which
the Attribute of value will be printed to the screen.
Use the following code and I always undefined
Thank you very much for your help
$(this).click(function (){ var val = $('#223').attr("value"); alert (val) ; })
<html> <head> <title>Page Title</title> <script src="https://code.jquery.com/jquery-3.1.1.js"></script> </head> <body> <p value="223">JQuery is </p> <p value="1.8">JQuery is </p> </body> </html>
Use p
instead of this
$('p').click(function (){
var val = $(this).attr("value");
alert (val) ;
})
Example with your code:-
$('p').click(function (){ var val = $(this).attr("value"); alert (val) ; })
<html> <head> <title>Page Title</title> <script src="https://code.jquery.com/jquery-3.1.1.js"></script> </head> <body> <p value="223">JQuery is </p> <p value="1.8">JQuery is </p> </body> </html>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.