Reputation: 32996
$target.is( "a.foo" )
will return true or false depending on if the target matches what's inside is().
What if I want to check what is() sees? What function do I use?
I tried alert($(target.is())
to see if I could find out what the target is, but I just got the value false.
Upvotes: 1
Views: 111
Reputation: 23142
All jQuery objects maintain their original selector in a property:
var $target = $('#originalSelector');
alert($target.selector); // Alerts '#originalSelector'
Upvotes: 0
Reputation: 71
i think this can help you
http://api.jquery.com/jQuery.type/
example is here :
jQuery.type(target);
Upvotes: 0
Reputation: 9374
For me it looks like you want to find out if the target was found. They way to do it:
if($target.length > 0){
//found
}
If you want to get node name do:
$target.get(0).nodeName
Upvotes: 0
Reputation: 7315
u can use is() to check some variables to return a function; it is very similar to hasClass method..
$('a').hover(function() {
$target = $(this);
if(!$target.hasClass('active')) {//or u can use is('#active') to check id
//to prevent same response on same object hover
$('a').removeClass('active');
$target.addClass('active');
$('.allPages').hide();
var getID = $target.attr('id');
$('#'+getID).show();
};
});
Upvotes: 0
Reputation: 7490
Would this not be a matter if using console.log on the object, and on the typeof of both the $target and a selector of a.foo?
ie
console.log($('a.foo'));
console.log(typeof($('a.foo')));
console.log($target);
console.log(typeof($target));
I assume this is what the .is() would be checking, testing the value and type of two objects, similar to '===' although I may be wrong
Upvotes: 0
Reputation: 144689
you can try event.target
:
The target property can be the element that registered for the event or a descendant of it. It is often useful to compare event.target to this in order to determine if the event is being handled due to event bubbling. This property is very useful in event delegation, when events bubble.
$('a').click(function(event){
var $target = $(event.target);
if( $target.is("a.foo") ) {
...
}
})
Upvotes: 1
Reputation: 236032
I'm not sure if I understand the question, but based on your topic, a similar jQuery function here would be .hasClass()
.
$target.hasClass('foo'); // true if $target contains a className 'foo'
Upvotes: 0