skeptic01 skeptic01 - 1 year ago 143
Javascript Question

navigating to prev element using jQuery

I am at the element with class fieldValidation(bolded below). And trying to navigate to the label field inside


Here's what I am doing.


The pattern of fTitleCell and fInputCell goes on for multiple fields and for each fInputCell, I need to traverse to the prev closest fTitleCell and grab its label.

<div class="fRow">

<div class="fTitleCell">
<input id="mainForm:j_idt139" type="checkbox" name="mainForm:j_idt139" class="checkbox-Access">
<label onmouseover="FA.fixLabelFor(this);">*IP Address*</label>

<span class="fInputCell searchField-ip_int" style="width:25.0%;">
<div xmlns="" xmlns:ga="">
<input type="text" name="mainForm:j_idt139" value="" class="fieldValidation" onblur="filter.setAdvCheckBox(this);" onkeyup="validation.checkType(this, 'ADDR');">


Answer Source

You need to go back to the parent. Then to the previous siblings element and after that look for the label.

JsFiddle as a working exemple.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download