How can i determine the value is changed in the select box without clicking the select box itself.
My code is as follows:
JQUERY
$("select").each(function() {
$(this).change(function() {
if ($(this).val() === "-Select-"){
this.parent().addClass("highlightSelect");
this.parent().sibling().show();
} else{
this.parent().removeClass("highlightSelect");
this.parent().sibling().hide();
}
});
});
HTML
<div id="wwctrl_add_savedAddressId" class="wwctrl styled-select">
<select id="add_savedAddressId" class="storedPaymentInput_size4 required savedAddress checkDropdown valid" onchange="changeSavedAddressType();generateSavedAddressAdd();" name="summaryData.usedAddress">
<option value="-Select-">-Select-</option>
<option value="O">Enter New Address</option>
<option value="3041">Home - 116 Parrot...</option>
<option value="22268">Other - rwara, aw...</option>
<option value="21372">Other - 1040..</option>
</select>
</div>
<div class="error" for="add_savedAddressId" generated="true" style="display: none;"> Select item</div>
Note: I have other buttons which affects the change of the value of the above select box
First – your code in question will not work.
It must be like this:
parent is jquery object function and not dom object function and
thisis a dom object which could be turned to jq object like this:$(this). Also, thers is notsiblingmethod in jquery, but there issiblings. Or, if you want to take next/previous sibling you can use.next()/.prev()instead ofsiblingswhich will return all siblings of an elementI removed each, but actually that is not required. You may use it, but almost any jquery method will do an operation with set of methods, so
$("select")may find few selects in page and$("select").change(...)will bind onchanged handler to all selects found by$("select").And answerign your question: as I understand you want to call change handler after selected value is changed porgrammatically. You can do that like this:
$("select").change(), but this way you will call change event on all selects, so you can do it like this:$("#add_savedAddressId").change(). In second case you will call a change even handler only for select with idadd_savedAddressId