$(document).ready(function() { $("button").click(function() { var firstObj = $("#content p").first(); console.log(firstObj[0]); // gets the first p element var lastObj = $("#content p").eq(1); console.log(lastObj[0]); // gets the p element at index 1 filteredObj = $("#content p").filter(".demo"); console.log(filteredObj[0]); // gets the p element with class demo }); });
<h2>jCombat Demo - jQuery DOM Manipulations</h2> <div id="content"> <p>This is a paragraph. <a href="#">Sample Link</a></p> <p class="demo">This is another paragraph.</p> </div> <button>Click here</button>