I googled and googled and I concluded that it\'s very hard to get answer on my own.
I am trying to use jquery or JavaScript to get a property of clicked element. I c
In jQuery, if you attach a Example: http://jsfiddle.net/wpNST/ This uses jQuery's .click(fn) method to assign the handler, but access the There are jQuery methods that do this as well, like .attr(). Example: http://jsfiddle.net/wpNST/1/ Here I wrapped the DOM element with a jQuery object so that it can use the methods made available by jQuery. The .attr() method here gets the class that was set.click
event to all $('div').click(function() {
var theClass = this.className; // "this" is the element clicked
alert( theClass );
});
className
property directly from the DOM element that was clicked, which is represented by this
.$('div').click(function() {
var theClass = $(this).attr('class');
alert( theClass );
});