jquery select element by class code example

Example 1: jquery select input with class

$("input.myClass:checkbox")

Example 2: jquery find tag and class

$(".txtClass")                  =>  getElementsByClassName()

$("#childDiv2 .txtClass")       =>  getElementById(),
                                    then getElementsByClassName()

$("#childDiv2 > .txtClass")     =>  getElementById(),
                                    then iterate over children and check class

$("input.txtClass")             =>  getElementsByTagName(),
                                    then iterate over results and check class

$("#childDiv2 input.txtClass")  =>  getElementById(),
                                    then getElementsByTagName(),
                                    then iterate over results and check class

Example 3: get element by id jqueryt

$( "#myDiv" )

Example 4: jquery select element with class

$('.classid')

Example 5: jquery find selected option by class

$(this).find('option:selected').attr("name");