0

If I have following html structure

<div class="col-lg-3 form-group">
    <input id="My_Value" class="form-control ui-autocomplete-input" type="text" value="" name="My.Value" autocomplete="off" data-toggle="tooltip" data-placement="right" data-original-title="Choose!">
    <span class="field-validation-valid" data-valmsg-replace="true" data-valmsg-for="My.Value"></span>
</div>
<div class="col-lg-1">
    <span class="glyphicon glyphicon-ok"></span>
    <span class="glyphicon glyphicon-remove"></span>
    <a class="" title="some title">
</div>

When traversing dom if I know My_Value how can I select glyphicon-ok. Worth to mention is there are many elements with glyphicon-ok class and I want to select only this first after My_Value selector.

4 Answers 4

3

Just answer

var span_glyphicon_ok  = $('#My_Value').parent().next().find('.glyphicon-ok:first');

parent() => for getting parent div of My_Value

next() => for getting next element of above div.

find() => find glyphicon-ok by class selector

Sign up to request clarification or add additional context in comments.

1 Comment

Also .find('.glyphicon-ok')[0];
0

Try:

You can first use .parent() to get parent of My_Value then go to .next() element and find glyphicon-ok element inside it.

$("#My_Value").parent("div").next().find(".glyphicon-ok:first")

Comments

0

In this Structure, your main DIV is col-lg-1 so you have just focus on that particular DIV.

<div class="col-lg-1">
    <span class="glyphicon glyphicon-ok"></span>
    <span class="glyphicon glyphicon-remove"></span>
    <a class="" title="some title">
</div>

you just want to pick first glyphicon from col-lg-1 so the process will be like below. and just add one class in the same div which has already class col-lg-9 like col-lg-9 glyphicon-wrapper.


.col-lg-9.glyphicon-wrapper > .glyphicon:first-of-type {
    /* Your CSS code will be here */
}


:first-of-type will be pick first glyphicon from the parent div.

Comments

-1

There are many jquery selector you want to use. Check below code:-

$('#My_Value').parent('.form-group').next().find('.glyphicon-ok:first')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.