javascript - Why is my :nth-child(2) selector not working in my jQuery? -
javascript - Why is my :nth-child(2) selector not working in my jQuery? -
i have next jquery:
$(".score-window a:first-child").click(function() { $(".score-window").hide(); $(".login-window").show(); }); $(".score-window a:nth-child(2)").click(function() { $(".score-window").hide(); $(".register-window").show(); });
which hooked next html:
<div class="score-window"> <i class="icon-remove" title="close"></i> <p>in order view score, have <a href="#">log in</a>.</p><br> <p>don't have business relationship yet? <a href="#">register</a>! totally free , you'll ability save scores.</p> </div>
i have 2 links in score-window
class, don't see why isn't working.
you have 2 links, each 1 kid of parent p
, match a:first-child
only. parent of links not .score-window
, p
. parent of p
elements (along i
, br
elements) is .score-window
.
you need amend selectors utilize :nth-child()
p
elements instead, select a
under each one. there's i
first child, , br
between 2 p
elements looks isn't needed. should able remove this:
$(".score-window p:nth-child(2) a").click(function() { $(".score-window").hide(); $(".login-window").show(); }); $(".score-window p:nth-child(3) a").click(function() { $(".score-window").hide(); $(".register-window").show(); });
if br
must remain there whatever reason, utilize p:nth-child(4)
or p:last-child
instead sec selector.
if you're using or can upgrade jquery 1.9, can utilize :nth-of-type()
instead limit count p
elements (i.e. first p
, sec p
), older versions of jquery don't back upwards it:
$(".score-window p:nth-of-type(1) a").click(function() { $(".score-window").hide(); $(".login-window").show(); }); $(".score-window p:nth-of-type(2) a").click(function() { $(".score-window").hide(); $(".register-window").show(); });
javascript jquery html jquery-selectors
Comments
Post a Comment