html - jQuery selectors issue -
So, I have a list with several items, each with 2DIVs in my display: none;
The problem is when it is clicked on the link every divs are visible.
HTML
& lt; Div class = "song-info" & gt; & Lt; Ul & gt; & Lt; Li class = "etter" & gt; & Lt; A href = "#" class = "licenses" & gt; LICRIS & LT; / A & gt; & Lt; / Li & gt; & Lt; Li class = "etree" & gt; & Lt; A href = "#" square = "credit" & gt; Credit & lt; / A & gt; & Lt; / Li & gt; & Lt; Li class = "purchase" & gt; & Lt; A href = "#" & gt; Buy & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; Span class = "playout" & gt; & Lt; / Span & gt; & Lt; / Li & gt; & Lt; Li class = "track-duration" & gt; (4:18) & lt; / Li & gt; & Lt; / Ul & gt; & Lt; / Div & gt; & Lt ;! - /.song-info - & gt; & Lt; Div class = "cf" & gt; & Lt; / Div & gt; & Lt; Div class = "container-lyricus" & gt; & Lt; A href = "http://www.nirvana.com" & gt; Nirvana & lt; / A & gt; Nevermind & lt; / Div & gt; & Lt; Div class = "container-credit" & gt; & Lt; A href = "http://www.nirvana.com" & gt; Nirvana & lt; / A & gt; Nevermind & lt; / Div & gt; js
$ (document) .ready (function () {$ (function () {var lycris = $ (". Lycris"); Var credits = $ ("credit"); $ (Laikis). Click (function () {$ ('container-sellers'). ToggleClass ("block");}); $ (credit). Function () {$ (container-credit). ToggleClass ("block");});});}); Assume thatand < Code> .container-credits In fact, you have given different names to identify between them (your description means that everyone is actually given the name), you have to target the other Must specify. Easily possible with thecontent.container-lycris data attribute.
$ (document) .ready (function () {$ (function () {var lycris = $ (". Lycris "); $ (Laikis). Click (function () {$ ('* [Data-id =' '+ $ (this) .data (' tar ') +' "] '). Toggleclass (" block ");});});});.container-lycris {display: none;} .block {display: block;}lang-html prettyprint-override">ul> a class = "license" data-TR = "2" href = "#" & gt; credit & lt; / a & gt; & lt; / li & gt; & lt; li class = "Purchase" & gt; & lt; a href = "#" & gt; Buy & lt; / a & gt; & lt; / li & gt; & Lt; Li & gt; & Lt; Span class = "plain" & gt; & Lt; / Span & gt; & Lt; / Li & gt; & Lt; Li class = "track-duration" & gt; (4:18) & lt; / Li & gt; & Lt; / Ul & gt; & Lt; / Div & gt; & Lt ;! - /.song-info - & gt; & Lt; Div class = "cf" & gt; & Lt; / Div & gt; & Lt; Div data-id = "1" class = "container-licensed" & gt; & Lt; A href = "http://www.nirvana.com" & gt; Nirvana & lt; / A & gt; Nevermind 1 & lt; / Div & gt; & Lt; Div data-id = "2" class = "container-licensed" & gt; & Lt; A href = "http://www.nirvana.com" & gt; Nirvana & lt; / A & gt; Jessfield: Because the functionality is similar between two
, becausethe functions you've done , Use only one class and specify differentclick ()
data id There is no reason to do two things that do the same thing.I hope it helps. ^^
Comments
Post a Comment