The element selector selects all elements that have the given html tag name. In javascript we use a similar function getElementsByTagName
to do this.
$('TagName')
TagName
is any html tag name like div,span,p etc.
selector | description |
---|---|
$('div') | Selects all elements with a tag name of div |
$('p') | Selects all elements with a tag name of p |
$('img') | Selects all image elements |
$('span') | Selects all elements with a tag name of span |
In following example,when the user click on the button,
A red border will be added to the elements that has a tag name of 'DIV'
example:Select element by html tag name using jQuery
Try now