How to get element with CSS class name and id using jquery

18-Dec-2019

.

Admin

Hi Guys ,

In this blog, i will talk how to jquery in get element with css class name and id. you can easy get element with CSS class name and id using jquery. we are html method using get element with CSS class name and id.

Exmaple Get Element For ID: #id


$(‘#idName’) – selects all elements that have an id of ‘idName’, regardless of its tag name.

$(‘div#idName’) – selects all div elements that has an id of ‘idName’.

Exmaple Get Element For Class: .classname

$(‘.className’) – selects all elements that have an class name of ‘className’, regardless of its tag name.

$(‘div.className’) – selects all div elements that has an class name of ‘className’.

Full Example

<html>

<head>

<title>JQuery Get element with class name and id - nicesnippets.com</title>

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.js"></script>

</head>

<body>

<h1>JQuery Get element with class name and id - nicesnippets.com</h1>

<div class="DemoClass">

This is belong to 'div class="DemoClass"'

</div>

<div id="TestId">

This is belong to 'div id="TestId"'

</div>

<script type="text/javascript">

$(document).ready(function(){

var $element = $('.DemoClass').html();

alert($element);

var $element = $('#TestId').html();

alert($element);

});

</script>

</body>

</html>

it will help you....

#Jquery