Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: Access the value of the element adjacent to the anchor tag

I have element structure as follows:

<div class="qty-adjust-inner">
    <a class="btn btn-min">
        <font style="vertical-align: inherit;"><font style="vertical-align: inherit;">-</font></font>
    </a>
    <div class="value">
        <input type="hidden" value="1" />
        <span data-bind="text: $parent.qty" class="qty_value">
            <font style="vertical-align: inherit;"> <font style="vertical-align: inherit;" class="">120</font></font>
        </span>
    </div>
    <a class="btn btn-plus">
        <font style="vertical-align: inherit;"><font style="vertical-align: inherit;">+</font></font>
    </a>
</div>

I need to increment/decrement the value "120" on .btn-min and .btn-plus class buttons.

I tried to access the value using var value = $('.btn-min').find('.value').html(); and also find, children but not getting the results.

Edit: As pointed out by @Taplar the value section is not a child of the anchor tag. The problem is there are many anchor tags like these, and I need to increment the very next adjacent value having class value

like image 325
GenZ Dev Avatar asked Mar 02 '23 03:03

GenZ Dev


1 Answers

As element containing .value class is a children of element containing .qty-adjust-inner you can search something like.

   $('.qty-adjust-inner').find(".value").find('span').text().trim()
like image 74
Asutosh Avatar answered Apr 25 '23 09:04

Asutosh