I am trying get the previous element. So when click in the .percen I want to alert the value of the previous element. At the moment I get undefined. What is the problem?
<input class="c currency" type="text" name="artigoAlternativo1_C"/>
<input class="d currency percen" type="text" name="artigoAlternativo1_D"/>
<br/>
<input class="c currency" type="text" name="artigoAlternativo1_C"/>
<input class="d currency percen" type="text" name="artigoAlternativo1_D"/>
$.fn.percentageFormat = function () {
this.each(function (i) {
$(this).change(function (e) {
var $curr = $(this);
$curr_ = $curr.prev('.c');
alert(this.value);
alert($curr_.prev().value);
});
});
return this;
}
$(function () {
$('.percen').percentageFormat();
});
You are calling the
prevmethod twice and jQuery object has novalueproperty, change:To:
or:
http://jsfiddle.net/2gf95/