JavaScript How can I access two “this” in a javascript member function access this javascript,access parent this javascript,access outer this

It's better and more modern practice to access the element (target) or current element the event is bubbling through (currentTarget). Using this is unclear inside a class for anything other than the class instance. Also it's better to use an event listener so multiple events can be attached of the same type.

SomeClass.prototype.someFunc = function(){
    const btn = document.crealeElement("button");
    btn.addEventListener('click', (event) => {
       this.somePropertyOfSomeClass = true; //this works, because arrow function has lexical scope
       event.target.classList.add("active"); // proper way to access the element
    }
}

Also you might want to take a look at ES6 classes.

Answer:1

Just save the context in the outside function:

SomeClass.prototype.someFunc = function(){
   let _this = this;
   var btn = document.crealeElement("button");
   btn.onclick = function() {
      _this.somePropertyOfSomeClass = true; //saved context
      this.classList.add("active");
   }
}
Answer:2

Replace this code this.classList.add("active"); to btn.setAttribute("class", "active");

 SomeClass.prototype.someFunc = function(){

    var btn = document.crealeElement("button");
    btn.onclick = function() {
       this.somePropertyOfSomeClass = true; //this works, because bind
      btn.setAttribute("class", "active"); //this may be help you
    }.bind(this);
}
Answer:3

this is my html <div> <h1 class="main-header logic-head av-settings-head"></h1> <div class="col-xs-12 col-xs-12 col-lg-12 tabcontent" > <form class="form-horizontal ...

this is my html <div> <h1 class="main-header logic-head av-settings-head"></h1> <div class="col-xs-12 col-xs-12 col-lg-12 tabcontent" > <form class="form-horizontal ...

I have created a sample typeorm project using the typeorm cli which has ormconfig.json by default: { "type": "postgres", "host": "localhost", "port": 5432, "username": "postgres", "...

I have created a sample typeorm project using the typeorm cli which has ormconfig.json by default: { "type": "postgres", "host": "localhost", "port": 5432, "username": "postgres", "...

I am using html2canvas.js to create a <canvas> image from a div on a page. What I'd like to do is send the rendered base64 image to a cfc via ajax so I can actually save the image to a folder on ...

I am using html2canvas.js to create a <canvas> image from a div on a page. What I'd like to do is send the rendered base64 image to a cfc via ajax so I can actually save the image to a folder on ...

  1. send base64 image to server
  2. send base64 image to web api c#
  3. send base64 image in email
  4. send base64 image to server python
  5. send base64 image postman
  6. send base64 image to server c#
  7. send base64 image in email java
  8. send base64 image to server angular 4
  9. send base64 image in json
  10. send base64 image in url
  11. send base64 image to server php
  12. send base64 image to server android
  13. send base64 image to server nodejs
  14. send base64 image to web api
  15. send base64 image in email c#
  16. send base64 image to server javascript
  17. send base64 image to server android volley
  18. send base64 image in email php
  19. send base64 image ajax
  20. send base64 image nodejs

I have the following setup where a custom checkmark is added to style the radio buttons. but it also adds that checkmark to the text type inputs. var changed =function(){ Array.from(...

I have the following setup where a custom checkmark is added to style the radio buttons. but it also adds that checkmark to the text type inputs. var changed =function(){ Array.from(...