2016-12-30 3 views
0

id 속성을 사용하지 않고 현재 태그를 DOM 요소로 선택할 수있는 방법이 있습니까?riotjs에서 DOM 요소로 현재 태그를 선택하는 방법

현재 수행중인 작업은 다음과 같습니다.

function addAttr(n,v){ 
    var ta = document.getElementById(opts.id); 
    ta.setAttribute(n,v); 
} 

나는 이와 같은 직접적인 방법을 찾고 있습니다. document.querySelector jQuery로하지만,하지와 this.root 작품을 전달

function addAttr(n,v){ 
    var ta = document.querySelector(this); 
    //var ta = document.querySelector(this.root); 
    ta.setAttribute(n,v); 
} 

()

Complete example

답변

0

나는 해결책을 얻었다. 나는 'mount'이벤트에서 코드를 옮겼다. 따라서 this.root을 사용할 수 있습니다. 이제 쿼리 선택기가 필요하지 않습니다. this.root는 그 자체로 작동합니다.

이제 직접 사용할 수 있습니다.

this.root.setAttribute(n,v); 

참조 용으로 대괄호 링크를 업데이트했습니다.

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; 
    } 
});