setattribute

setAttribute and video.src for changing video tag source not working in IE9

守給你的承諾、 提交于 2019-11-26 09:08:48
问题 I have literally read every stackoverflow thread regarding changing the video tag source dynamically via javascript in IE9, including the useful but not agreed upon posts here and here, but do feel like there is another solution. Here is the very basic example of what I\'m trying to do: var video = document.getElementById(\'video\'); //now, use either of the lines of code below to change source dynamically video.src = \"nameOfVideo\"; //or use... video.setAttribute(\"src\", \"nameOfVideo\");

When to use setAttribute vs .attribute= in JavaScript?

爷,独闯天下 提交于 2019-11-25 23:43:45
问题 Has a best-practice around using setAttribute instead of the dot ( . ) attribute notation been developed? E.g.: myObj.setAttribute(\"className\", \"nameOfClass\"); myObj.setAttribute(\"id\", \"someID\"); or myObj.className = \"nameOfClass\"; myObj.id = \"someID\"; 回答1: You should always use the direct .attribute form (but see the quirksmode link below) if you want programmatic access in JavaScript. It should handle the different types of attributes (think "onload") correctly. Use getAttribute