0% found this document useful (0 votes)
24 views

Jquery Methods: //this Is Used To Refer To The Currently Selected Element

This document summarizes jQuery methods for selecting elements, setting event methods, and provides an example code reference. To select elements, jQuery uses the $() function with selectors like "element*filter1+*filter2+ sub-element[filter1][filter2]". Event methods are set using $(element).on(eventName, function(){}). The example code handles a checkbox change event to dynamically modify a dropdown based on the checkbox state.

Uploaded by

Jeremy Farmer
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Jquery Methods: //this Is Used To Refer To The Currently Selected Element

This document summarizes jQuery methods for selecting elements, setting event methods, and provides an example code reference. To select elements, jQuery uses the $() function with selectors like "element*filter1+*filter2+ sub-element[filter1][filter2]". Event methods are set using $(element).on(eventName, function(){}). The example code handles a checkbox change event to dynamically modify a dropdown based on the checkbox state.

Uploaded by

Jeremy Farmer
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

jQuery Methods

To select an element.
$(element*filter1+*filter2+ sub-element[filter1][filter2])
Each filter is an attribute value pair. Eg input*type=checkbox+*title=Abstract+

Setting event methods
$(select and elemnt).on(eventName,function(), -);

Event names can be= hover, click, change etc. in function write your custom code.

Understand the following code for reference
$("input[type='checkbox'][title='Abstract']").on('change',function(){
//this is used to refer to the currently selected element
if($(this).prop('checked'))
{
var subType=$("select[title='Submission type']");
var firstOption=$("select[title='Submission type'] option:first").val();
if(!(firstOption==new String('Abstract').valueOf()))
{
// append abstract
subType.prepend("<option value='Abstract'>Abstract</option>");
}
//disabling what is selected
$("select[title='Submission type'] option:selected").prop('selected',false);
//selecting abstract
$("select[title='Submission type'] option:first").prop('selected','selected');

}
else{
var firstOption=$("select[title='Submission type'] option:first").val();
if(firstOption==new String('Abstract').valueOf())
{
//remove abstract from drop down
$("select[title='Submission type'] option[value='Abstract']").remove();
}
//select first value as default value;
$("select[title='Submission type'] option:selected").prop("selected",false);
$("select[title='Submission type'] option:first").prop("selected","selected");
}
});

You might also like