JQuery

Click a button/link when page load,find selected and unselected options in Jquery

 

Click a button when page load

$(document).ready(function () {

              $("#link").click(function () {
                 alert("link clicked");
              });

              $("#btnSearch").click(function () {
                 alert("button clicked");
              });

              $("#btnSearch").trigger('click'); // OR
              $("#btnSearch").click();


});
<input type="button" id="btnSearch" value="Search"/>

Click a hyperlink

 $('#link').click();

<a href="#" id="link" >Go</a>

Find selected and unselected options

 $(document).ready(function () {
              $("#sel").find('option:selected').css('background', "red");
              $("#sel").find('option:not(:selected)').css('background', "blue");

 });
<select id="sel" >
    <option value="USA">USA</option>
    <option value="SriLanka" selected="selected">SriLanka</option>
    <option value="India">India</option>
    <option value="Japan">Japan</option>
</select>

1 comment: