Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7860709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:23:48+00:00 2026-06-02T22:23:48+00:00

If I manually write those following lines in an HTML file: <div> <input type=button

  • 0

If I manually write those following lines in an HTML file:

<div>
<input type="button" value="Button 1">
<input type="button" value="Button 2">
</div>

A text node will be created for each new line.

I wanted to understand the useCapture argument of addEventListener method.
I choosed to access DOM elements using childNodes property of my div element but I will have to ignore textNodes between elements. This isn’t really practical:

document.getElementsByTagName("div")[0].addEventListener("click", function(){alert(1);}, true);

document.getElementsByTagName("div")[0].childNodes[1].addEventListener("click", function(){alert(2);}, false);

document.getElementsByTagName("div")[0].childNodes[3].addEventListener("click", function(){alert(3);}, false);

Here you see that I have to ignore childNodes[0] and childNodes[2] in order to select my 2 input tags.

Is there a way to bypass textNodes creation without writing all HTML code just on one line and without using Javascript createElement?

Is it possible to write HTML code without creating textNodes when going to new line?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T22:23:49+00:00Added an answer on June 2, 2026 at 10:23 pm

    Firstly, don’t repeat yourself ! You’re repeating the same DOM query over and over.

    Try this:

    var div = document.getElementsByTagName("div")[0];
    div.addEventListener("click", function(){alert(1);}, true);
    
    var buttons = div.getElementsByTagName("button");  
    buttons[0].addEventListener("click", function(){alert(2);}, false);
    buttons[1].addEventListener("click", function(){alert(2);}, false);
    

    calling getElementsByTagName to get the buttons trivially skips the text nodes – problem solved!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to manually edit some of the files inside of the .cmp file
How to manually create Friendly URLs? (PHP) So I have created simple php file
I can connect manually by doing: M-x sql-postgres and type the User, Database, Host,
Given the following table (how to format those correctly here?) primary secondary A a
in jquery 1.4.2, ff 3.6.6: The following code produces three divs, which write messages
Is it possible to write a C function that does the following? Allocate a
I'm in the brainstorming process for a system that will be used to write
I'm trying to write a wysiwyg editor using a contentEditable div, and am having
In the following markup, "image 3" would the only visible div if all .image
I attempted to write the following code to draw a cylinder. The cylinder was

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.