1

Here are the different parts of my code

part1

<ul class="tabs">
  <li><a class="tab1" href=""></a></li>
  <li><a class="tab2" href=""></a></li>
  <li><a class="tab3" href=""></a></li>
  ...
</ul>

and part2

<div class="field-items">
  <div class="field-item">tab1</div>
  <div class="field-item">tab3</div>
  ...
</div>

How to make a condition so that if in Part 2 it has the values "tab1" and "tab3", then Part 1 is modified to contain these classes:

<li class="hiden"><a class="tab1" href=""></a></li>
...
<li class="hiden"><a class="tab3" href=""></a></li>
...

2 Answers 2

2

Something like this should work for you:

$(document).ready(function(){
    $("div.field-items div.field-item").each(function(){
       $("." + $(this).html()).parent().addClass("hiden");
    }); 
});
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks. And how do if such a relationship?<li><a class="tab1" href="">111</a></li> and part2 <div class="field-item">111</div>
Would you correct this .jQuery(document).ready(function($){ $('.field-item').each(function() { var tabname = $(this).text(); if(tabname == 'tab1' || tabname == 'tab3') { $('.tabs li a').hasClass(tabname).parent().addClass("hiden"); } }); }).
@Siteogra: It can be done easily by adding a selector :econtains to jQuery. I've set up an example forking your last jsfiddle: jsfiddle.net/5RzxN/1 Enjoy :)
0

Probably something like this:

$('.field-item').each(function()
{
    $('.' + this.innerHTML).addClass('hiden');
});

Maybe a little bit of modification, but should do the trick.

Comments

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.