0

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 ?

1
  • i know, that tag <noindex> is not valid. Commented Feb 4, 2014 at 17:28

1 Answer 1

3

You can try like this,

all_h1.each(function()
{
  if($(this).closest('noindex').length > 0)
  {
    //it is contained inside of <noindex>
  }
});
Sign up to request clarification or add additional context in comments.

2 Comments

@user3271784 So you want to check the immediate child of noindex. right.?
i want check contains <noindex> some <h1> (<h2> or other).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.