How to get element with CSS class name and id using jquery
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....
- How to Show Loading Spinner in JQuery?
- How to Create Ajax Submit Form Using jQuery?
- How To Get Current Page URL, Path, Host and hash using jQuery?
- How To Get, Set and Delete Div Background Image jQuery?
- JQuery Remove All Unwanted Whitespace From String Example
- Body Background Video Using Vide Jquery Example
- JQuery UI Autocomplete Example
- JQuery Split String By Comma Into Array Example