Is there any way to select current tag as DOM element without using id attribute?
What I'm currently doing is;
function addAttr(n,v){
var ta = document.getElementById(opts.id);
ta.setAttribute(n,v);
}
I'm looking for some direct way like this;
function addAttr(n,v){
var ta = document.querySelector(this);
//var ta = document.querySelector(this.root);
ta.setAttribute(n,v);
}
Passing this.root
works with jQuery but not with document.querySelector()
I got the solution. I moved my code in 'mount' event. So this.root
is available. Now I don't need query selector. this.root works in itself.
Now I can directly use;
this.root.setAttribute(n,v);
I have updated plunker link for reference.
this.on("mount",function(){
if(opts.fa){
this.root.className += " faa";
if(opts.selectable)
this.root.innerHTML = fa_icons[opts.fa];
else{
this.root.setAttribute("faicon", fa_icons[opts.fa]);
}
}else if(opts.text){
this.root.innerHTML = opts.text;
}
if(opts.transform){
this.root.style.transform = opts.transform;
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.