Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

142
Views
Javascript : Why can't I use the "this" with childnodes?
<div id="test" onmouseover="working(this)">
<p>help</p>
<p>me</p>
</div>

<div id="test" onmouseover="not_working(this)">
<p>help</p>
<p>me</p>
</div>

When I use the first function(not_working) it doesn't work, but when I used the second function(working) it does.

function not_working(element){
document.getElementById(element).childNodes[1].innerHTML="succeed";}

function working(element){
document.getElementById("test").childNodes[1].innerHTML="succeed";}

Sorry if I miss something simple, I'm still learning html and only have limited knowledge on javascript.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

this is a reference to the element, the event was created from (the div in your case), but getElementById takes an id ("test" in your case).

Also the hovered element is already being passed in the function as element so you can just do:

function working(element) {
    element.childNodes[1].innerHTML="succeed"
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!