Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
572 views
in Technique[技术] by (71.8m points)

jquery: how to get the value of id attribute?

Basic jquery question. I have an option element as below.

<option class='select_continent' value='7'>Antarctica</option>  

jquery

$(".select_continent").click(function () {
  alert(this.attr('value'));
});

This gives an error saying this.attr is not a function so im not using "this" correctly.

How can i get it to alert 7?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need to do:

alert($(this).attr('value'));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...