what to do at the end of next() or prev() in jquery

jQuery Selectors

In this department, you lot will learn most jQuery selectors and how to find DOM element(south) using selectors.

The jQuery selector enables you to find DOM elements in your web page. Most of the times you volition start with selector office $() in the jQuery.

$(selector expression,            context)              jQuery(selector expression,            context)          

The selector expression parameter specifies a pattern to match the elements. The jQuery uses CSS selector patterns too every bit its own pattern to match the elements.

The context parameter is optional. It specifies elements in a DOM hierarchy from where jQuery starts searching for matching elements.

Let's come across usually used selectors in jQuery.

Select Elements by Name

The most common selector pattern is element name. Specifing an element proper name as string east.g. $('p') will return an array of all the <p> elements in a webpage.

The following figure shows which DOM elements will be returned from $('p') & $'(div').

jQuery Selectors Demo
jQuery Selectors Demo

As you tin can encounter in the above figure, $('div') volition return all the <div> elements including its child elements.

            $('p').append('This is paragraph.');              // appends text to all p elements                            $('div').append('This is div.);              // appends text to all div elements                            <              div              >              <              p              >              </              p              >              <              p              >              </              p              >              </              div              >              <              p              >              </              p              >              <              div              >              </              div              >                      

Select Elements by Id

jQuery append() method inserts text at the end in the element.

You can get a particular element by using id selector pattern. Specify an id of an element for which you lot want to get the reference, starting with # symbol.

The post-obit effigy shows which DOM elements will be returned from $('#myDiv1') & $'(#prg2').

jQuery Selectors Demo
jQuery Id Selector Demo
            $('#impPrg').suspend('This element\'due south id is "impPrg"');  $('#myDiv2').append('This chemical element\'s id is "myDiv2"');              <              div              id              ="myDiv1"              >              <              p              >              </              p              >              </              div              >              <              p              id              ="impPrg"              >              </              p              >              <              div              id              ="myDiv2"              >              </              div              >                      

Select Elements by Attribute

jQuery besides allows you to find an element based on attributes fix on it. Specifing an attribute proper name in square brackets in $ function e.g. $('[class]') volition return all the elements that have class aspect irrespective of value.

In the post-obit example, jQuery returns all the elements that have class or contenteditable attribute irrespective of any value.

jQuery Selectors Demo
jQuery Attribute Selector
            $('[class]').append('This element has class attribute');              <              div              id              ="myDiv1"              >              <              p              >              </              p              >              </              div              >              <              p              id              ="impPrg"              course              ="boldPrg"              >              </              p              >              <              div              id              ="myDiv2"              class              ="yellowDiv"              >              </              div              >                      

You can also specify a specific value of an attribute in aspect selector. For example, $('[class="myCls"]') will return all the elements which have course aspect with myCls as a value.

jQuery Selectors Demo
jQuery Selector by Aspect Value
            $('[class="yellowDiv"]').suspend('This element includes class="yellowDiv" attribute');              <              div              id              ="myDiv1"              >              <              p              >              </              p              >              </              div              >              <              p              id              ="impPrg"              class              ="boldPrg"              >This is paragraph.</              p              >              <              div              id              ="myDiv2"              class              ="yellowDiv"              >              </              div              >                      

jQuery Selector Patterns

jQuery provides number of means to select a specific DOM element(s). The following table lists the nigh important selector patterns.

Category Selector Description
Observe chemical element $('div') Find all <div> elements
$('p, div, code') Notice <p>,<div> and <code> elements
Find descendant elements $('div p') Discover all <p> elements which are descendants of <div>
$('div > p') Notice <p> which is kid of <div>
$(*) Find all elements
Observe by Id $('#myDiv') Find element whose id is myDiv
$('div#myDiv') Find <div> element whose Id is myDiv
$('#myDiv1, #myDiv2') Detect multiple elements past id separated by comma.
Find by CSS class $('.myCSSClass') Find all the elements with grade=myCSSClass.
$('.myCSSClass1, .myCSSClass2 ') Finds all elements whose class attribute is set to myCSSClass1 or myCSSClass2
$('div.myCSSClass') Finds all <div> elements with course=myCSSClass
Find kid chemical element $('p:first-child') Detect all <p> elements, which is the commencement kid of its parent element. (parent element can be anything)
$("p:last-child") Selects all <p> elements which is the last child of its parent element. (parent chemical element tin can be annihilation)
$("p:nth-kid(5)") Selects all <p> elements which is the fifth child of its parent element. (parent element can be anything)
$("p:nth-last-child(2)") Selects all <p> elements which is the second last kid of its parent element. (parent chemical element can be anything)
$("p:only-child") Selects all <p> elements which is the just child of its parent chemical element. (parent element tin can be anything)
Observe by aspect $('[class]') Detect all the elements with the form attribute(whatever the value).
$('div[class]') Discover all the <div> elements that have a class attribute(whatever the value).
Observe by containing value of attribute $('div[class=myCls]') Notice all the <div> elements whose class attributes are equal to myCls.
$('div[class|=myCls]') Find all the <div> elements whose class attributes are either equal to myCls or starting with myCls cord followed by a hyphen (-).
$('div[class *="myCls"]') Selects <div> elements whose form attributes contain myCls.
$('div[class~=myCls]') Selects div elements whose class attributes contain myCls, delimited by spaces.
$("div[class $= 'myCls']") Selects <div> elements whose course attribute value ends with myCls. The comparison is instance sensitive.
$("div[class != 'myCls']") Selects <div> elements which do not have course attribute or value does non equal to myCls.
$("div[class ^= 'myCls']") Selects <div> elements whose course attribute value starts with myCls.
$("div:contains('tutorialsteacher')" Selects all <div> elements that contains the text 'tutorialsteacher'
Find past input type $(":input") Selects all input elements.
:button $(":button") Selects all input elements where blazon="button".
:radio $(":radio") Selects all input types where blazon="radio"
:text $(":text") Selects all input elements where type="text" .
":checkbox" $(":checkbox") Selects all checkbox elements.
:submit $(":submit") Selects all input elements where type="submit".
:password $(":password") Selects all input elements where type="password".
:reset $(":reset") Selects all input elements where type="reset".
:image $(':paradigm') Selects all input elements where type="image".
:file $(':file') Selects all input elements where type="file".
:enabled $(':enabled') Selects all enabled input elements.
:disabled $(':disabled') Selects all disabled input elements.
:selected $(':selected') Selects all selected input elements.
:checked $(':checked') Selects all checked input elements.
:hidden $(':hidden') Selects all hidden elements.
:visible $(':visible') Selects all visible elements.
:odd $('tr:odd') Selects all odd rows. (one,three,5,7..)
:fifty-fifty $('tr:even') Selects all fifty-fifty rows.(0,2,iv,6..)

Visit selector reference to know more selector patterns.

Desire to check how much you lot know jQuery?

watterstongreped1996.blogspot.com

Source: https://www.tutorialsteacher.com/jquery/jquery-selectors

0 Response to "what to do at the end of next() or prev() in jquery"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel