is it possible in jquery to get the value .attr() of (this) object?
an alert(this) returns true[object HTMLInputElement] so the == wont work
$("#tag1, #tag2").keyup(function(event){
if(this == "#tag1"){
alert("This is tag1");
};
if(this == "#tag2"){
alert("This is tag1");
};
thx
Art
It is not possible to get the selector that caused the current element to be matched – there are many possible selectors for a given element. While it would be theoretically possible if the jQuery object created by
$("#tag1, #tag2")was still available, it would be incredibly ugly.However, you can simply use
this.idto access the element’s ID ('tag1'or'tag2'in your case) and use it in your code:If there is no common code at all for the two elements it’s much better to use two selectors and functions instead of putting everything in a single function.