Reputation: 257
I am a newbie web developer. I am stuck in somewhere and I need your help. I have a filter() which works perfectly fine when I use it with an ID selector such as ('#test'). But when I try to pick the same element with it's class like ('.locate'), It doesn't work. By the way, $(result) comes from another html file via AJAX.
HTML:
<h1 id="test" class="locate">About Me</h1>
JS:
var outcome=$(result).filter('#test'); //It works
var outcome=$(result).filter('.locate'); //It doesn't
EDIT: Just now, I realized if it is a string that I give in html() or text(), it works. But if it is the variable itself,it doesn't. Here, jsfiddle.net/3UeSK/2
Upvotes: 0
Views: 993
Reputation: 16145
I think @PedroEstrada is right. You can see the working example here:
<h1 id="test" class="locate">About Me</h1>
<h2 id="result"></h2>
var result = $("h1");
var outcome = $(result).filter('.locate');
if(outcome.length > 0){
$("#result").text("found it");
} else {
$("#result").text("didn't find it");
}
Upvotes: 1