Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to get child element in javascript


            
                
            
         let content = document.getElementById('menu');
let firstChild = content.firstChild.nodeName;
console.log(firstChild);Code language: JavaScript (javascript)
Comment

javascript child element selector

// given html
    <div class="parent">
        <div class="child1">
            <div class="child2">
            </div>
        </div>
    </div>
    
// Get parent
let parent = document.querySelector('.parent'); 
// child element selector
parent.querySelector('.child')
Comment

javascript get tag child elements

var child_element = document.querySelector("#id").children[0];
//Where # defines id and '.' a class. And 0 argument the first child element
Comment

select child element javascript

/*
<div id="parent">
	<input value="off" />
    <button type="button">Click Me</button>
</div>
*/

const input = document.querySelector('#parent input');
const button = document.querySelecctor('#parent button');
Comment

how to get child element in javascript


            
                
            
         let firstChild = parentElement.firstChild; 
Code language: JavaScript (javascript)
Comment

how to get child element in javascript


            
                
            
         let lastChild = parentElement.lastElementChild;Code language: JavaScript (javascript)
Comment

PREVIOUS NEXT
Code Example
Javascript :: submit form react js 
Javascript :: how to write a variable in js 
Javascript :: Javascript seperate string number with dots 
Javascript :: javascript spread array without duplicates 
Javascript :: nginx get request method 
Javascript :: js decrease opacity canvas 
Javascript :: filter an array 
Javascript :: javascript return first match in array 
Javascript :: functions in javascript 
Javascript :: null value check in react js 
Javascript :: background colour in react 
Javascript :: javascript check if consecutive array 
Javascript :: framer motion for react 
Javascript :: extract the last number of two digits number js 
Javascript :: nodejs add element to array 
Javascript :: transform date to relative date js 
Javascript :: wavesurf js 
Javascript :: how to import scss file in angular 
Javascript :: how to generate random text in vue js 
Javascript :: function prototype javascript 
Javascript :: in vs of javascript 
Javascript :: install json ubuntu 
Javascript :: vue js get routes 
Javascript :: js event target 
Javascript :: vue 3 install eslint 
Javascript :: react window.addEventListener 
Javascript :: simple node rest 
Javascript :: how to add id in jquery 
Javascript :: nginx reverse proxy redirect 
Javascript :: array length in javascript 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =