Reputation: 1101
i have HTML which looks something like this (the inputs have no ID or CLASS, some of them have other attributes such as VALUE)
<div id="yoo">
<div class="check">
<input .......>
<input .......>
<input .......>
</div>
<div class="check">
<input .......>
<input .......>
<input .......>
</div>
</div>
I need to be able to target a specific input from only one of the "check" divs using Jquery I have tried the following
$("#sam .check input").remove() - this removes all the inputs. $("#sam .check").eq(1).remove() - this removes the selected input from both "check"s $("#sam .check").eq(1).("input").eq(2).remove() - I was hoping this would select a specific check element and within it select a specific input element, it does not work.
How do I select just one of the check elements and then select just one of the input elements within?
Is there any way to select a specific input element based on its index if there are a unknown number of other children (which are not inputs)?
Is there any way to select an element based on a attribute-value pair?
Upvotes: 0
Views: 183
Reputation: 46
To select a specific input you can use the nth-child selector
$('.check input:nth-child(2)').remove();
That will remove the second input of every element with the class check
.
To remove from only one check
div you could do the following:
$('.check:nth-child(1) input:nth-child(2)').remove();
That will remove the second input of the first element with the class check
.
To select based on attribute-value pair just do this:
$('[attribute="value"]').remove();
Or if you like to point to a specific element with a specific argument:
$('input[value="whatever"]').remove();
Upvotes: 1
Reputation: 648
so you only want to select the checkboxes under the first div? you could always give them the same class name, IDs need to be unique. something like this:
change the divs to:
<div class="check">
<input .......>
<input .......>
<input .......>
</div>
then this selector should remove the checkboxes.
$('.check:first input[type=checkbox]').remove();
not sure if that's exactly what you were going for, but hope it helps
Upvotes: 0