user3271784
user3271784

Reputation: 53

Find JQuery object in other JQuery object

sorry for my bad english

i have html

<noindex>
<h1>This is h1 in noindex</h1>
<div>
  <h1>This is h1 in noindex and in div</h1>
  <div>
  <h1>This is h1 in noindex and in div>div</h1>
  </div>
</div>
<h2>This is h2 in noindex</h2>
</noindex>

<h1>This is h1</h1>
<h2>This is h2</h2>

then, in js

var all_h1 = $('h1');
var all_h2 = $('h2');
all_h1.each(function()
{
  if($($(this),'<noindex>'))
  {
    //do somthing only with $(this)
  }
});

i know, that this is not work. i use has(), find(), $.contains and other, but its not work. How can search some jq.object in other jq.object ?

Upvotes: 0

Views: 72

Answers (1)

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

Reputation: 67207

You can try like this,

all_h1.each(function()
{
  if($(this).closest('noindex').length > 0)
  {
    //it is contained inside of <noindex>
  }
});

Upvotes: 3

Related Questions