We will use a checkbox with ID “myCheckbox” in this example First to check a checkbox using JQuery use the following code, remember to replace “myCheckbox” with the ID of your checkbox $('#myCheckbox').attr('checked','checked'); To un-check the checkbox use the following JQuery code, remember to replace “myCheckbox” with the ID of your checkbox $('#myCheckbox')...
Adding inline styles to html element using JQuery
This can be done by using the css JQuery function. Read more
An example is
$("#myElement").css('border','1px solid #FF0066');
The example above will produce the following
<input style="1px solid #FF0066" id="myElement" />
How to add a new Select Box option after the second option in the Select Box using JQuery
<select id="options"> <option>Option 1</option> <option>Option 2</option> <option>Option 3</option> </select> If you want to add a new option under Option 1, you would need to use the JQuery after function as example below $("#options option:first").after("<option>New second option</option>"); The above will find the first option and...
How to check if an html element exists with an specific ID using JQuery
This can be achieved by using .length
if($("#id_name").length == 0) {
//the element with id_name does not exists
}
How to add a new options to JQuery Chosen Plugin Dynamically
If users is the id of the select Chosen dropdown box, then use JQuery to append new options dynamically as in the example below
$("#users").append('<option value="1">User</option>').trigger("chosen:updated");
.trigger(“chosen:updated”); refreshes the Chosen dropdown box with the new option.
How to count the number of options in a select box using JQuery
This can be done using the jQuery length property
You will use the following command to determine if there are any options within the select box.
var length = $('#selectBoxId > option').length;
console.log(length);
#selectBoxId should be replaced with the ID of your select box.