jQuery - change value of an input of the previous div
I have this kind of code :
function changeValue(el) {
}
<div class="tracklistOff">
...
<div class="sideon">
...
</div>
<div class="trackon">
...
</div>
<div class="sideon">
...
</div>
<div class="trackon">
...
</div>
<div class="sideon">
<span class="sideindex"><input type="hidden" name="sidesOriginal[]" value="#" /></span>
</div>
<div class="trackon">
<span class="trackbotton"><a href="#" onClick="changeValue(this);return false">Edit</a></span>
</div>
<div class="sideon">
...
开发者_StackOverflow社区 </div>
<div class="trackon">
...
</div>
<div class="sideon">
...
</div>
<div class="trackon">
...
</div>
...
</div>
and i'd like to change the value of sidesOriginal[] to "hello" by clicking on Edit and using only the this reference as starting position. I'll change only that value, on the previous sideon, not for each sideon. How can I do it in jQuery?
Working example: http://jsfiddle.net/peeter/qy3h9/
$(this).parent().parent().children('.sideon').children('input[type="hidden"]').val('hello');
精彩评论