getelementsbytagname

My Greasemonkey script is not finding the elements (links) on the page?

时光怂恿深爱的人放手 提交于 2019-11-27 19:35:16
问题 The website is: lexin.nada.kth.se/lexin/#searchinfo=both,swe_gre,hej; My script is: function main(){ var links=document.getElementsByTagName("a"); alert("There are " + links.length + "links."); } main(); Running the script gives me two alert messages saying There are 0 links. Any ideas why I can't get the right amount of links from the document? And why do I get the alert twice? 回答1: The alert fires more than once because that page contains iFrames (with, de facto, the same URL as the main

How to insert metatag without using jquery append?

两盒软妹~` 提交于 2019-11-27 16:40:20
问题 I used the following jquery to insert a metatag into a html document. <script type="text/javascript"> if(screen.width>=320 && screen.width<=767){ $('head').append('<meta id="viewport" name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">');} </script> If possible, I'd like to insert the metatag without using jquery. Anyone have any ideas how I can do that? I believe I will probably need to use document.getElementByTagName but I'm not sure how. Just in

addEventListener to an article element in Javascript

浪子不回头ぞ 提交于 2019-11-27 16:29:46
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(

addEventListener to an article element in Javascript

倖福魔咒の 提交于 2019-11-27 04:08:47
问题 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

js之tab选项卡以及排思想

天大地大妈咪最大 提交于 2019-11-27 03:58:10
排它思想 选中一个排除其他的 1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title></title> 6 <style> 7 .active{ 8 background-color: blue; 9 } 10 #aaa{ 11 width: 50px; 12 height: 70px; 13 background-color: red; 14 position: absolute; 15 top: 30px; 16 display: none; 17 18 } 19 20 #box{ 21 width: 50px; 22 height: 30px; 23 background-color: blue; 24 position: relative; 25 } 26 </style> 27 </head> 28 <body> 29 <button>按钮1</button> 30 <button>按钮2</button> 31 <button>按钮3</button> 32 <button>按钮4</button> 33 <button>按钮5</button> 34 35 <div id="box"> 36 哈哈哈<div id="aaa"></div> 37 </div> 38

javascript TypeError: document.getElementsByTagName(“p”)[0].innerHtml is not a function

梦想的初衷 提交于 2019-11-26 17:14:49
问题 I'm getting the following error for a simple function below: TypeError: document.getElementsByTagName("p")[0].innerHtml is not a function I'm just trying to understand the usage of getElementsByTagName. function myFunc(){ document.getElementsByTagName("p")[0].innerHtml("hello my name is vaani"); } </script> </head> <body onload="myFunc();"> <p></p> <p></p> <p></p> </body> Can someone tell me on where i'm going wrong? 回答1: innerHTML but not innerHtml , and it is not a function, you should set

JavaScript: Loop through all the elements returned from getElementsByTagName

假装没事ソ 提交于 2019-11-26 15:28:19
I am trying to loop through all the elements retruned from getElementsByTagName("input") using forEach. Any ideas why this does not work in FF, Chrome or IE? <html> <head> </head> <body> <input type="text" value="" /> <input type="text" value="" /> <script> function ShowResults(value, index, ar) { alert(index); } var input = document.getElementsByTagName("input"); alert(input.length); input.forEach(ShowResults); </script> </body> </html> You need to convert the nodelist to array with this: <html> <head> </head> <body> <input type="text" value="" /> <input type="text" value="" /> <script>

How to loop through all the elements returned from getElementsByTagName [duplicate]

佐手、 提交于 2019-11-26 03:59:34
问题 This question already has an answer here: For loop for HTMLCollection elements 12 answers I am trying to loop through all the elements retruned from getElementsByTagName(\"input\") using forEach. Any ideas why this does not work in FF, Chrome or IE? <html> <head> </head> <body> <input type=\"text\" value=\"\" /> <input type=\"text\" value=\"\" /> <script> function ShowResults(value, index, ar) { alert(index); } var input = document.getElementsByTagName(\"input\"); alert(input.length); input