javascript - addClass on all matches attribute -


I have three containers in which there is a specialty I want to add a class for all elements of the match on such a parent. The usual features are: If I click on any of the sidebar, the main content area or header class must be added to all matching attributes. (Something like triggering all three attributes on one click).

The code below is:

  & lt; ul class = 'main-nav' & gt; & Lt; Li & gt; & Lt; A link-tab = "left-department" href = "" & gt; Department & lt; / A & gt; & Lt; / li & gt; & Lt; / Ul & gt; & Lt; ul class = 'Content tab-container' & gt; & Lt; Li & gt; & Lt; A link-tab = "left-department" href = "" & gt; Department & lt; / A & gt; & Lt; / li & gt; & Lt; / Ul & gt; & Lt; ul class = 'sidebar' & gt; & Lt; Li & gt; & Lt; A link-tab = "left-department" href = "" & gt; Department & lt; / A & gt; & Lt; / li & gt; & Lt; / Ul & gt;   
  var linkTab = $ ('li a [link-tab]'); $ (LinkTab) .on ('click', function (e) {e.preventDefault (); $ (linkTab) .Parent ('li'). AddClass ('active');});   

Please help, how do I get it?

Try something like this:

  $ ("a [Link-tab] "). (Click on 'click', function (e) {e.preventDefault (); var attributeName = $ (this) .attr ("link-tab"); var matchedLinks = $ ("a [link-tab =" + AttributeName + "]"); Linked Links ("Lee"). AddClass ("Active");});   

This idea is to see all those anchors that have the same link-tab value, in your case lt- Department . After that, . Active class add their li parents.

Comments

Popular posts from this blog

ruby on rails - How to avoid ActionController::InvalidCrossOriginRequest exception? -

Selenium IDE Conditional Statements -

How to edit the second line in text file using batch? -