JQuery: Retrieve and update SINGLE span value inside a (wordpress) loop -


i've been struggling 2 days, because have little knowledge in jquery / javascript, , think i've searched thoroughly many times didn't answer need.

i'm working wordpress loop, each loop item has: span class, , link trigger update via jquery span's value / content.

what have far is: when click trigger-link - let's on first loop-item, of span's value / content on of item loop updated. i'm trying achieve simple as: when click trigger-link on first loop-item, update span's value / content on loop-item only.

here's html:

<div class="loop-item>  <span class="count">123</span>  <span><a class="update"></a></span>  <p>some text</p> </div>  <div class="loop-item>  <span class="count">123</span>  <span><a class="update"></a></span>  <p>some text</p> </div>  <div class="loop-item>  <span class="count">123</span>  <span><a class="update"></a></span>  <p>some text</p> </div>  <div class="loop-item>  <span class="count">123</span>  <span><a class="update"></a></span>  <p>some text</p> </div> 

here's jquery:

$(document).ready(function(){  $(".update").click(function(){   var countval = $(".count").text();   var nuval = countval + 1;   $(".count").text(nuval);  }); }); 

i know it's entirely wrong jquery code. i'm willing learn , hoping here willing right.

thanks.

update:

the working jquery codes follow (modified nuval variable):

$(document).ready(function(){  $(".update").click(function(){   var countspan = $(this).closest(".loop-item").find(".count");   var countval = countspan.text();   var nuval = parseint(countval) + 1;   countspan.text(nuval);  }); }); 

thank you!

this 1 easy enough, see 2 main issues first saying here is:

$(".count").text(nuval); 

is changing items class count.

second loop item divs missing quote @ end of class:

<div class="loop-item> 

if understand correctly looking accomplish this: on click of link element class "update" change value of span element of class "count" within same loop-item div.

here how can accomplish task:

$(document).ready(function(){  $(".update").click(function(){   // container of class .loop-item , grab span element of class count   // , store element in countspan variable   var countspan = $(this).closest(".loop-item").find(".count");    var countval = countspan.text();   var nuval = countval + 1;   countspan.text(nuval);  }); }); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -