[jQuery] Get all elements by class name
Sample Code
<!DOCTYPE html>
<html>
<head>
<title>Sample : Get all elements by class name</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
</head>
<body>
sdfdsfsdf
<div class="element">1</div>
<p>testing</p>
<div class="element">2</div>
<div id="wrapper">I got sth</div>
<div class="element">3</div>
<script>
$( document ).ready(function() {
$('.element').each(function(index, item) {
console.log(item);
});
});
</script>
</body>
<html>
Result
Reference
http://stackoverflow.com/questions/4735342/jquery-to-loop-through-elements-with-the-same-class
No comments :
Post a Comment