javascript - Add id to a child of a visible element -
How can I write this in jQuery:
If .horse Is visible, then add #cat to .dog (but only .dog which is visible .horse Is the child of>)?
& lt; Div id = "tabs-1" class = "horse" style = "margin-right: 20px; display: none;" & Gt; & Lt; Div style = "width: 70%; margin: 0 auto; margin-top: -20px" & gt; & Lt; Div class = "rabbit" & gt; & Lt; One class = "dog" href = "movie.mov" & gt; & Lt; / A & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; Div id = "tabs-2" class = "horse" style = "margin-right: 20px; display: block;" & Gt; & Lt; Div style = "width: 70%; margin: 0 auto; margin-top: -20px" & gt; & Lt; Div class = "rabbit" & gt; & Lt; One class = "dog" href = "movie.mov" & gt; & Lt; / A & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt;
Use the following, it will work
$ ('.horse: visible .dog'). Attr ('id', 'cat')
Comments
Post a Comment