S[0] What is the bottom? (S is a jquery object)
Code: Var s=$ ("div"); alert (s.length); alert (s[0]);
jquery objects have a 0 index by default.
S is a jquery object
S[0] For DOM elements you can use all the properties and methods of the DOM
You can determine, based on the length property, how many DOM element objects are contained in total.
Take object by: s[0],s[1],s[2] ...
#id matches an element based on the given ID. $ ("#id1")
Element matches all elements according to the given element name $ ("div")
What is the object of this in jquery?
The study found that this and s[0] refer to the same object, the DOM element object selected by jquery.
jquery Select option Operations related knowledge >>
JQuery is a very powerful JS class library, now the more used to feel more useful.
How do I manipulate the Select (drop-down box) using jquery? The main story is how to dynamically add option dynamically select option, if our select control's ID property is SEL
jquery clears option $ ("#sel"). empty ();
jquery adds option $ ("#sel"). Append (' <option value= ' 1 "> Dynamic add </option> ');
jquery Select option $ ("#sel"). Val (1); You can use this to set the value of 1 in Select to Selected
jquery Gets the text and value selected by select:
1. $ ("#select_id"). Change (function () {//code ...}); Add an event for Select, which is triggered when one of the items is selected
2. Var checktext=$ ("#select_id"). Find ("option:selected"). Text (); Gets the text selected by the Select
3. Var checkvalue=$ ("#select_id"). Val (); Gets the value selected by select
4. Var checkindex=$ ("#select_id"). Get (0). SelectedIndex; Gets the index value of the Select selection
5. Var maxindex=$ ("#select_id option:last"). attr ("index"); Gets the maximum index value of the Select
jquery Add/Remove option for select:
1. $ ("#select_id"). Append ("<option value= ' value ' >Text</option>"); Append an option to the Select (drop-down item)
2. $ ("#select_id"). Prepend ("<option value= ' 0 ' > Please select </option>"); Insert an option for select (first position)
3. $ ("#select_id option:last"). Remove (); Delete index value in select maximum option (last)
4. $ ("#select_id option[index= ' 0 ']"). Remove (); Delete option with index value 0 in select (first)
5. $ ("#select_id option[value= ' 3 ']"). Remove (); Delete option for value= ' 3 ' in select
5. $ ("#select_id option[text= ' 4 ']"). Remove (); Delete option for text= ' 4 ' in select
Content empty:
$ ("#charCity"). empty ();
jquery Object [0] What is the bottom?