how do I use current node instead of this?

gaurav

JS

var menuBtn = document.getElementsByClassName('btn-block');
var lenOfMenuBtn = menuBtn.length;
for (var i = 0; i < lenOfMenuBtn; i++) {
    menuBtn[i].addEventListener('click',addMenu,false);
}

function addMenu() {
    addOkFlag();
    //addToCart();
    //removeOkFlag();
}

function addOkFlag() {
    var elmnt = document.createElement('i');
    elmnt.setAttribute('class','glyphicon glyphicon-ok');
    this.appendChild(elmnt);
} 

Error is "this.appendChild is not a function". I want to call multiple function when user click the button so I call first function where I want to add <i> tag in it but I don't how to pass current node from addEventListener to append this child.

baao

You can pass the clicked element to the function

var menuBtn = document.getElementsByClassName('btn-block') ;
var lenOfMenuBtn = menuBtn.length ;
for (var i = 0; i < lenOfMenuBtn; i++) {
    menuBtn[i].addEventListener('click',addMenu,false) ;
}

function addMenu(e) {
    addOkFlag(e.target) ;
    // or addOkFlag(this);

}

function addOkFlag(el) {
    var elmnt = document.createElement('i');
    elmnt.setAttribute('class','glyphicon glyphicon-ok');
    el.appendChild(elmnt);
} 

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I configure Notepad++ to use spaces instead of tabs?

How do I determine the current operating system with Node.js

How do I get the path to the current script with Node.js?

How do I use PHP to get the current year?

How do I change Eclipse to use spaces instead of tabs?

How do I uninstall PIL for python 2.7 and use Pillow instead?

Xpath | how do I know if the current node has a specific class or not

How do I use Any() instead of RemoveAll() to exclude list items?

How do I use IsError on a function value, instead of cell value?

How do I force the DotNet Framework to use JIT instead of NGEN?

In Vue CLI how do I use sass instead of node-sass (default for sass-loader)?

How do I use HMSET with node promisify

How do I use reduce function instead of recurring function?

How do I make Heroku use node 14.x instead of 12.x?

How do I use my current credentials with Remote Desktop?

How do I NOT use DependencyResolver.Current.GetService(...) in this situation

How do I force compiler to use aggregate init instead of constructor

Rails: How do I select the current user instead of all the users?

How do I use an array instead of the variables in this repetitive function?

How do I use json instead of plist to populate TableView

How do I use jQuery Post/Ajax instead of form submit?

Given a current list node how do I insert an item, x, correctly after the node referenced by current?

How do I make Alien use an existing tarball instead of downloading?

HOw do I use the index as a reference instead of the date

How do I use async pipe instead of using subscribe?

How do I use "Ctrl" key and "V" in Windows 10 to "Paste" to a directory selected with the mouse instead of the current directory?

SwiftUI how do I use .textFieldStyle(.myTextFieldStyle) instead of textFieldStyle(MyTextFieldStyle())

How do I use the current MUI state to sum and display columns?

How do I use patterns instead of colors in a county map?