I'm using jQuery Mobile which creates a lot of the DOM for you. I need to remove() radio buttons, but based on how the HTML is constructed in jQuery Mobile, I do not have an id for the parent div. I can easily grab both the input and labels, but need to also get rid of the our div to completely removed the entry styling from the list of radio buttons.
我正在使用jQuery Mobile为你创建了很多DOM。我需要删除()单选按钮,但根据如何在jQuery Mobile中构建HTML,我没有父div的id。我可以很容易地抓住输入和标签,但还需要摆脱我们的div来完全删除单选按钮列表中的条目样式。
<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>
3 个解决方案
#2
10
Since the <div>
element is the immediate parent of your <input>
element, you can use the aptly-named parent() method:
由于
$("#ahBkMj").parent().remove();
In the general case, if you want the first ancestor matching a selector, you can use closest():
在一般情况下,如果您希望第一个祖先匹配选择器,您可以使用nearest():
$("#ahBkMj").closest("div").remove();
Note, however, that closest()
includes the element itself in its search.
但请注意,nearest()在搜索中包含元素本身。
#3
0
this works for me.....
这对我有用.....
var child = '# or . and name of your child div... ';
var child ='#或。和你孩子的名字...';
var width = Math.round($(child).parent().width());
#1
#2
10
Since the <div>
element is the immediate parent of your <input>
element, you can use the aptly-named parent() method:
由于
$("#ahBkMj").parent().remove();
In the general case, if you want the first ancestor matching a selector, you can use closest():
在一般情况下,如果您希望第一个祖先匹配选择器,您可以使用nearest():
$("#ahBkMj").closest("div").remove();
Note, however, that closest()
includes the element itself in its search.
但请注意,nearest()在搜索中包含元素本身。
#3
0
this works for me.....
这对我有用.....
var child = '# or . and name of your child div... ';
var child ='#或。和你孩子的名字...';
var width = Math.round($(child).parent().width());