Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
130
rated 0 times [  136] [ 6]  / answers: 1 / hits: 64202  / 13 Years ago, tue, april 26, 2011, 12:00:00

How to get the id on an object, i know the id is hola, but i need to get it during runtime



alert($('#hola').id);


The idea is this:



<script>

(function ($) {

$.fn.hello = function(msg) {
alert('message ' + msg);
alert('is from ' + this.id); // this.id doesn't work
};

})(jQuery);


$('#hola').hello('yo');

</script>

More From » jquery

 Answers
38

Use attr() to read attributes:



alert($('#hola').attr('id'));

[#92561] Sunday, April 24, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
elliem

Total Points: 415
Total Questions: 117
Total Answers: 94

Location: American Samoa
Member since Fri, Aug 26, 2022
2 Years ago
;