How to use each loop with class element of html in Jquery?

How to use each loop with class element of html in Jquery?

In this post we will give you information about How to use each loop with class element of html in Jquery?. Hear we will give you detail about How to use each loop with class element of html in Jquery?And how to use it also give you demo for it if it is necessary.

Whenever you need to use each loop in jquery then you can follow this example code. each with html class you can get whole object of that class using $(this) jquery function. In following example you can see i get attribute data-id using $(this).data(‘id’), that means you can take current class data attribute value.

Example:

<html lang="en">

<head>

<title>Each Loop with Class Jquery</title>

<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

</head>

<body>

<ul>

<li data-id="1">Apple</li>

<li data-id="2">Banana</li>

<li data-id="3">Mango</li>

<li data-id="4">Chairy</li>

</ul>

<script type="text/javascript">

$('.item-list').each(function() {

var data_id = $(this).data("id");

console.log(data_id);

});

</script>

</body>

</html>

Hope this code and post will helped you for implement How to use each loop with class element of html in Jquery?. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

3  +  7  =  

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US