How to get parent in jQuery when child is known?

I use jQuery Mobile, which creates a lot of DOM for you. I need to remove () the switches, but based on how the HTML is built in jQuery Mobile, I don't have the ID of the parent div. I can easily capture both input and labels, but I also need to get rid of our div in order to completely remove the input style from the list of radio buttons.

<div class="ui-radio"> <input type="radio" value="ahBkMj" id="ahBkMj" name="spam" data-theme="c"> <label for="ahBkMj" class="ui-btn ui-btn-icon-left ui-btn-up-c"> <span class="ui-btn-inner"> <span class="ui-btn-text">Foo</span> <span class="ui-icon ui-icon-ui-icon-radio-off ui-icon-radio-off"></span> </span> </label> </div> 
+7
source share
3 answers

Will jQuery .parent() do?

+12
source

Since the <div> element is the immediate parent of your <input> element, you can use the aptly-named parent () method

 $("#ahBkMj").parent().remove(); 

In general, if you want the first ancestor to match the selector, you can use the closest () :

 $("#ahBkMj").closest("div").remove(); 

Note, however, that closest() includes the element itself in its search.

+10
source

it works for me .....

var child = '# or. and the name of your child div ... ';

 var width = Math.round($(child).parent().width()); 
0
source

All Articles