jQuery

How to disable all html form elements within a DIV tag using JQuery

H

NOTE: Please not that the prop JQuery function should be used instead of the attr function in JQuery 1.6 and higher Answer: To disable all input elements within div use the following code: $(‘#message :input’).attr(‘disabled’, true); To disable all select elements within div use the following code: $(‘#message :select’).attr(‘disabled’, true);...

How to find the id of the first anchor html element within the first element of an unordered list using JQuery

H

With getting the id I mean getting the attribute id’s value for the first element within the first element of the unordered list tag.   Answer: We can obtain this by using the :first Selector from JQuery. Read more about the selector here Example: HTML  <ul class="custom_class">     <li><a href="test1.html" id="1" name="link1" /></li>     <li><a...

How to get the id of the first html element within a div tag element using JQuery

H

How to get the id of the first img html tag element within a specific div tag using JQuery? With getting the id I mean getting the attribute id’s value for the first element within the div tag.   Answer: We can obtain this by using the :first Selector from JQuery. Read more about the selector here Example: HTML <div class=”custom_div”>     <img id="1" name="image1"...

How to check if JQuery library is loaded

H

Use the following code withing your JavaScript tags 

if(jQuery){ 
    alert('jQuery loaded'); 
}else{
    alert('jQuery not loaded');
}

This method can be used to check if any other JavaScript variable or function exists or is set and thus is not limited to jQuery alone.

How to get the value of a radio button within a radio button group when selected using JQuery

H

Give all the radio buttons within a group the same name <input type="radio" name="RADIOGROUP" value="1" /> <input type="radio" name="RADIOGROUP" value="2" /> <input type="radio" name="RADIOGROUP" value="3" /> <input type="radio" name="RADIOGROUP" value="4" /> Now use the following JQuery code to obtain the value for the selected radio button within the Group...

How to submit an HTML Form using JQuery

H

For example you have a form with id “myform“ <form id="myform" action="submit.php">   <input type="text" value="This is a test form" />   <input type="button" id="mybutton" value="Save" /> </form> Now  when the button with id “mybutton” is clicked we want to submit the form using the JQuery submit() function which executes each time the specified...

How to use JQuery to make a field Read Only

H

Say you have a input text field as below <input type="text" name="inputField" id="inputField" /> As soon as the page has finished loading we will make use of JQuery to make the input field Read Only so that the field can’t be edited by the user. We do it like this <script type="text/javascript">   jQuery(document).ready(function($){      $('#inputField').attr('readonly'...

About Author

Ian Carnaghan

I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment.

Follow Me