This First Child Jquery Code Example


Example 1: first child element javascript


Both these will give you the first child node:

console.log(parentElement.firstChild); // or
console.log(parentElement.childNodes[0]);

If you need the first child that is an element node then use:

console.log(parentElement.children[0]);

Example 2: jquery first child


$('div:first-child')

Example 3: jquery first child


$( "li" ).first().css( "background-color", "red" );

Example 4: select the first elemnt have class in jquery


<script>
// jquery
$( "tr:first" ).css( "font-style", "bold" );
</script>

Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android SDK Location Should Not Contain Whitespace, As This Cause Problems With NDK Tools