Home > Web Front-end > JS Tutorial > JQuery adds/removes nodes to elements such as select_jquery

JQuery adds/removes nodes to elements such as select_jquery

WBOY
Release: 2016-05-16 17:38:19
Original
1263 people have browsed it

jQuery gets the Text and Value selected by Select:

Copy code The code is as follows:

var checkText= jQuery("#select_id").find("option:selected").text(); //Get the Text selected by Select
var checkValue=jQuery("#select_id").val(); //Get the Select Selected option Value
var checkIndex=jQuery("#select_id ").get(0).selectedIndex; //Get the selected index value
var maxIndex=jQuery("#select_id option:last"). attr("index"); //Get the maximum index value of Select

jQuery adds/removes the Option item of Select:
Copy code The code is as follows:

jQuery("#select_id").append("") ; //Insert an Option for Select (the first position)
jQuery("#select_id option:last").remove(); //Remove the Option with the largest index value in Select (the last one)
jQuery( "#select_id option[index='0']").remove(); //Delete the Option with index value 0 in Select (the first one)
jQuery("#select_id option[value='3'] ").remove(); //Delete Option with Value='3' in Select
jQuery("#select_id option[text='4']").remove(); //Delete Text=' in Select 4' Option

Clear content:
Copy code The code is as follows:

jQuery("#select_id").empty();
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template