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

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

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

Hi Dev’s, Today now In this blog, i will talk with you how to jquery in get element with css class name and also id. So we can easy get element also with CSS class name and id by using jquery. Now we are html method by using get element also with CSS class name and id.

Exmaple Get Element For ID: #id

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

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

Exmaple Get Element For Class: .classname

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

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

Full Example

<html>
<head>
	<title>JQuery Get element with class name and id - Codingspoint.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 - Codingspoint.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>

Read also : How To Set Bcc And Cc Mail Address In Laravel Mail?

I hope it will help you. Also you can follow us on Facebook

close

You may also like