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

196
Views
why 'this' is undefined in my JQ funtion?

"this" is not working show_siblings

function addHeading(){
        $(".content").append("<h1 class='content_heading'>Heading <span onclick='show_siblings()' ><svg xmlns='http://www.w3.org/2000/svg' height='18' width='20'><path d='M5.688 11.083q-.459 0-.771-.323-.313-.322-.313-.76 0-.458.323-.771.323-.312.761-.312.458 0 .77.323.313.322.313.76 0 .458-.313.771-.312.312-.77.312Zm4.312 0q-.458 0-.771-.323-.312-.322-.312-.76 0-.458.323-.771.322-.312.76-.312.458 0 .771.323.312.322.312.76 0 .458-.323.771-.322.312-.76.312Zm4.312 0q-.458 0-.77-.323-.313-.322-.313-.76 0-.458.313-.771.312-.312.77-.312.459 0 .771.323.313.322.313.76 0 .458-.323.771-.323.312-.761.312Z'/></svg><div class='contentChildOptions'><button>Copy</button><button>Duplicate</button><button>Delete</button></div></span> </h1>");
        $(".content_heading").attr("contentEditable","true");
        $(".content_heading > *").attr("contentEditable","false");
        document.getElementById("heading_options").style.display = "block";
    }
function show_siblings(){              
    $(this).children().toggleClass("showElement");
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

```this`` reference missing in your code

function show_siblings(){              
    $(this).children().toggleClass("showElement");

See the example I demystifying this and that keyword

let element1 = document.getElementById("element1");
let element2 = document.getElementById("element2");

let toggle = true;

function toggleFunc( that ) {
  toggle = !toggle;
  that.setAttribute("data-show", toggle );
}
[data-show="false"] {
 color: red
}

[data-show="true"] {
 color: green
}
<div id="toggle" onclick=toggleFunc(this)>Click here: 1</div>

<div id="showElement" onclick=toggleFunc(this)>Click here: 2<div>

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!