I am trying to addEventListener to all article elements so when they are clicked it turns them into a draggable element.
I'm not using jQuery on this task.
Attempt 1:
document.getElementsByTagName("ARTICLE").addEventListener('click', function(){
document.getElementsByTagName("ARTICLE").setAttribute('draggable', true);});
Attempt 2:
function draggableTrue() {
var addDrag = document.getElementsByTagName("article");
addDrag.setAttribute('draggable', true);
}
//add event listener to articles
var draggableArticles = document.getElementsByTagName("article");
draggableArticles.addEventListener('onclick', draggableTrue);
In both I am getting a "Uncaught TypeError: undefined is not a function" which usually points out I am missing something, but after reading up I can't figure out what.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…