javascript - How can I make this for only one element? -
this code works spans in page. should set this
specific one?
class="snippet-code-js lang-js prettyprint-override"> var next = function(e) { var current = $('.active'); var prev = $('#prev'); pos = $('.active').attr('id'); $("#num").text('(' + pos + '/' + researchplaces.length + ')'); $(current).next().attr("class", "active"); $(current).attr("class", "passive"); e.stoppropagation(); }
class="snippet-code-html lang-html prettyprint-override"><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="address"><a id="prev">prev </a> <span id="address" class="active">0 elgin street</span> <span id="address" class="passive">1 elgin street</span> <span id="address" class="passive">2 elgin street</span> <span id="address" class="passive">3 elgin street</span> <span id="address" class="passive">4 elgin street</span> <span id="address" class="passive">5 elgin street</span> <span id="address" class="passive">6 elgin street</span> <span id="address" class="passive">7 elgin street</span> <span id="address" class="passive">8 elgin street</span> <span id="address" class="passive">9 elgin street</span> <a id="next"> next</a> </div>
<div class="container"> <span id="address1" class="passive active">0 elgin street</span> <span id="address2" class="passive">1 elgin street</span> <span id="address3" class="passive">2 elgin street</span> <span id="address4" class="passive">3 elgin street</span> <span id="address5" class="passive">4 elgin street</span> <span id="address6" class="passive">5 elgin street</span> <span id="address7" class="passive">6 elgin street</span> <span id="address8" class="passive">7 elgin street</span> <span id="address9" class="passive">8 elgin street</span> <span id="address10" class="passive">9 elgin street</span> </div>
now js example
$(function(){ var current = $('.active'); var prev = $('#prev'); $('.active').on('click',function(){ alert(this.id); }); });
so if active changes can utilize this
in click event. html , js help clarify went wrong. 1 time state pos
, researchplace
should i'll update you.
javascript jquery
No comments:
Post a Comment