Jquery find nearest matching element

后端 未结 4 1734
Happy的楠姐
Happy的楠姐 2020-12-28 11:16

I have a series of rows with columns and I want to select the value of an input field that is in a previous column to the input field (price input)

相关标签:
4条回答
  • 2020-12-28 12:00
    var otherInput = $(this).closest('.row').find('.inputQty');
    

    That goes up to a row level, then back down to .inputQty.

    0 讨论(0)
  • 2020-12-28 12:00

    You could try:

    $(this).closest(".column").prev().find(".inputQty").val();

    0 讨论(0)
  • 2020-12-28 12:05

    closest() only looks for parents, I'm guessing what you really want is .find()

    $(this).closest('.row').children('.column').find('.inputQty').val();
    
    0 讨论(0)
  • 2020-12-28 12:11

    Get the .column parent of the this element, get its previous sibling, then find any input there:

    $(this).closest(".column").prev().find("input:first").val();
    

    Demo: http://jsfiddle.net/aWhtP/

    0 讨论(0)
提交回复
热议问题