Reputation: 4073
HTML:
<option data-task-hours="100" value="1"> - Parent Task</option>
<option data-task-hours="50" value="2"> - - Child task 1 </option>
<option data-task-hours="25" value="3" class="third-level-child"> - - - Sub Child task 1.1</option>
<option data-task-hours="50" value="5"> - - Child task 2</option>
To hide options with value I can use
$("#selectlistID option[value='3']").hide();
How can I hide all the option elements using class which are sub-childs ?
Upvotes: 1
Views: 76
Reputation: 82241
You can use contains selector:
$("#selectlistID option:contains('- - -')").hide();
Update: Using class selector-
$('option.third-level-child').hide();
Upvotes: 1
Reputation: 559
You have to select the option by class as shown below,
$("#selectlistID option[class='third-level-child']").hide();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<select id="selectlistID">
<option data-task-hours="100" value="1"> - Parent Task</option>
<option data-task-hours="50" value="2"> - - Child task 1 </option>
<option data-task-hours="25" value="3" class="third-level-child"> - - - Sub Child task 1.1</option>
<option data-task-hours="50" value="5"> - - Child task 2</option>
</select>
Upvotes: 0