javascript - How do I find the value of a variable in a specific string in jquery? -


this kinda confusing best...

so writing program when clicks on text, subtracts amount total. example html this....

<form> <input type='number' name='namea' id='ida' step='0.01'> </form> <div id='diva></div> 

and javascript/jquery looks this...

$('input[name=namea]').change(function(){     var itemvalue = this.value;     $('#diva').prepend('<p class = "pa">blah blah ' + itemvalue + 'blah blah.</p>'); }); var total = 100; 

and part confused on..

$('.pa').click(function() {     //i want find itemvalue of 1 click on , subtract total. }) 

so can find current value of itemvalue... how find of string prepend few strings ago.

thanks in advance help.

since clicking on dynamically added element, can store itemvalue data element

ex

jquery(function($){     $('input[name=namea]').change(function(){         var itemvalue = this.value;         var pa = $('<p />', {             class: 'pa',             html: 'blah blah ' + itemvalue + 'blah blah.'         }).data('itemvalue', itemvalue).data('otherdata', 'othervalue')         $('#diva').prepend(pa);     });      $('#diva').on('click', '.pa', function() {         alert($(this).data('itemvalue'))         alert($(this).data('otherdata'))     }) }) 

it give values of itemvalue n time back

demo: fiddle


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -