JavaScript javascript equivalent of jquery all children selector javascript equivalent jquery document ready,javascript equivalent jquery find,javascript

I have the following jquery selector which I am trying to convert to regular javascript.

$("#lelement>*").on("dblclick", function(){
});

what would the equivalent be with regular javascript ? Can I do this ?

document.getElementById('element').childNodes.addEventListener("dblclick", function(e){
});
Answer:1

One elegant, non-jQuery way to do this would be via querySelectorAll():

    document.querySelectorAll('#lelement > *').forEach(function(node) {
        node.addEventListener("dblclick", function(e){
           console.log('double clicked on child of #element');
        });
    })
p {
margin:1rem;
background:red;
color:white;
}
<div id="lelement">
<p>Double click me - Child 1</p>
<p>Double click me - Child 2</p>
</div>
Answer:2

You'll have to explicitly iterate over all elements which match the #lelement>* selector (the collection can be obtained with querySelectorAll), and then attach a handler to each of them:

document.querySelectorAll('#lelement > *').forEach((child) => {
  child.addEventListener('dblclick', () => console.log('double clicked!'));
});
<div id="lelement">
  <div>content 1</div>
  <div>content 2</div>
</div>
Answer:3

I have 5 boxes and an array of items. How do I display 5 items in 5 boxes, randomly selected without repetition? Is it a problem with: ptags[index].textContent = item[0].label; that it is not ...

I have 5 boxes and an array of items. How do I display 5 items in 5 boxes, randomly selected without repetition? Is it a problem with: ptags[index].textContent = item[0].label; that it is not ...

Often in the interview questions it is heard that Why one should use redux form in the ReactJs instead of simple form. which extra ordinary facilities it provides to the developer ? Then what should ...

Often in the interview questions it is heard that Why one should use redux form in the ReactJs instead of simple form. which extra ordinary facilities it provides to the developer ? Then what should ...

  1. redux form simple example
  2. redux form simple
  3. react redux simple form example
  4. react redux simple form

I am trying to use phantomjs to automate the process of login into facebook. The issue is that facebook uses js codes to set cookies before the login form is submitted. Clicking on the email input box ...

I am trying to use phantomjs to automate the process of login into facebook. The issue is that facebook uses js codes to set cookies before the login form is submitted. Clicking on the email input box ...

  1. phantomjs read cookies

var j = jQuery.noConflict(); j.fn.portionHeight = function(ratio){ var width = j(this).width(); var height = Math.floor(width*ratio); j(this).height(height); } function initAndResize(){ ...

var j = jQuery.noConflict(); j.fn.portionHeight = function(ratio){ var width = j(this).width(); var height = Math.floor(width*ratio); j(this).height(height); } function initAndResize(){ ...