The CSS attribute selectors selects an element from the HTML using CSS properties.
An element can be selected using the
name attribute with the following syntax:
In the syntax above,
^ indicates ‘starts with’ and
＄ indicates ‘ends with.’
The HTML consists of a form that contains four input elements. Every input element has a name associated with it. The dependency for jQuery is included in the HTML via the
script tag in line 6.
_nameare selected using the
[input$="_name"]selector expression. The elements with the
student_last_namenames are selected. Then, we change the background color of the elements to green.
[input="_name"]selector expression. The element named
zipare selected using the
[input^="zip"]selector expression. The element named
zipis selected. Then, we change the background color of the element to red.
getElementsByName()method of the
documentobject. The selected element is passed to the
$()selector function. This can be used as a jQuery object. The element’s background color is changed to yellow.
View all Courses