jQuery Get Element By Tag name


jquery jQuery Get Element By Tag name Jquery Introduction

How can we access the HTML element using jQuery ?

We can access the HTML elements by name in jQuery very easy easily as compared to the simple JavaScript.

Example of Get Element By Tag name Using jQuery

<script type="text/javascript"> $("button").click(function() { $("button").css("color","red"); }); </script>

Output Select Element By Tag Name jQuery

Syntax jQuery Selector

$("TagName")

Select Button on Index 2

$("button").eq(1).css("color","red"); Index will start from 0.
  • First button index will be Zero i.e eq(0)
  • Second button index will be one i.e eq(1) and so on.

How to access Element without the Index and choose the clicked Element?

Using $(this)

we will select the current clicked Element.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <button> First Button </button> <button> Second Button </button> <script type="text/javascript"> $("button").click(function() { $(this).css("color","red"); }); </script>

Output:

jquery Jquery Introduction Chapter Next »