setattribute

Javascript: setAttribute() v.s. element.attribute = value to set “name” attribute

蹲街弑〆低调 提交于 2019-11-27 14:42:50
So I'm learning to manipulate the DOM and I noticed one interesting thing: Let's say I want to set the name attribute of an element by using the "." dot notation: element.name = "someName"; console.log(document.getElementsByName("someName")[0]); // returns "undefined"?? However if I use the document.setAttribute() method, it works fine: element.setAttribute("name", "someName"); console.log(document.getElementsByName("someName")[0]); // returns the element like it should. Not sure why the dot notation method doesn't work in the first case. Why does this happen? My guess (because you didn't

setAttribute, onClick and cross browser compatibility

橙三吉。 提交于 2019-11-27 09:44:30
I have read a number of posts about this but none with any solid answer. Here is my code: // button creation onew = document.createElement('input'); onew.setAttribute("type", "button"); onew.setAttribute("value", "hosts"); onew.onclick = function(){fnDisplay_Computers("'" + alines[i] + "'"); }; // ie onew.setAttribute("onclick", "fnDisplay_Computers('" + alines[i] + "')"); // mozilla odiv.appendChild(onew); Now, the setAttribute() method (with the mozilla comment) works fine in mozilla but only if it comes AFTER the line above it. So in other words it seems to just default to whichever gets

How to access id attribute of any element in Raphael

与世无争的帅哥 提交于 2019-11-27 06:10:40
问题 I'm using Raphael for drawing some elements on a website. The elements include rectangle, line (path). I have given an id to the path element and trying to access it in the onclick event of that line. but when I do an alert of the id, nothing is visible. Following is the code snippet function createLine() { var t = paper.path("M" + xLink + " " + yLink +"L" + linkWidth + " " + linkHeight); t.attr('stroke-width','3'); t.attr('id','Hello'); t.node.onclick = processPathOnClick; } function

javascript setattribute to multiple element

巧了我就是萌 提交于 2019-11-27 02:26:22
问题 I have many div with the class publish_0 that I would like to change to publish_1 on click of a button. Right now I use this but it only change one item. How to I apply the setattribute to all item that have the publish_0 . document.querySelector('.publish_0').setAttribute("class", "publish_1"); 回答1: You can use this with jquery: $(".publish_0").attr("class", "publish_1") Alternatively, use getElementsByClassName and loop through the DOM elements returned. 回答2: You need to use a loop to

Using request.setAttribute in a JSP page

让人想犯罪 __ 提交于 2019-11-26 23:08:15
问题 Is it possible to use request.setAttribute on a JSP page and then on HTML Submit get the same request attribute in the Servlet ? 回答1: No. Unfortunately the Request object is only available until the page finishes loading - once it's complete, you'll lose all values in it unless they've been stored somewhere. If you want to persist attributes through requests you need to either: Have a hidden input in your form, such as <input type="hidden" name="myhiddenvalue" value="<%= request.getParameter(

Javascript: setAttribute() v.s. element.attribute = value to set “name” attribute

久未见 提交于 2019-11-26 22:25:15
问题 So I'm learning to manipulate the DOM and I noticed one interesting thing: Let's say I want to set the name attribute of an element by using the "." dot notation: element.name = "someName"; console.log(document.getElementsByName("someName")[0]); // returns "undefined"?? However if I use the document.setAttribute() method, it works fine: element.setAttribute("name", "someName"); console.log(document.getElementsByName("someName")[0]); // returns the element like it should. Not sure why the dot

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

瘦欲@ 提交于 2019-11-26 22:04:57
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"); Both of these lines of code are hated thoroughly by Internet Explorer, notably because the src is most

Replace setAttribute with IE compatible script

我与影子孤独终老i 提交于 2019-11-26 21:56:02
问题 I am trying to create a pop-up message that disables the rest of the screen until you confirm it, only by using CSS and JavaScript (and without the alert function). Although http://msdn.microsoft.com/en-us/library/ie/ms536739%28v=vs.85%29.aspx declares that setAttribute is supported in IE8 and higher, it does not seem to work correctly - well, actually it doesn't seem to work at all. Here is my code: <html> <style type="text/css"> .overlay { position: absolute; left: 0px; top: 0px; width: 100

Angularjs dynamically set attribute

十年热恋 提交于 2019-11-26 20:35:03
问题 I'm trying to dynamically add attribute to div in controller in angular js. var table = document.getElementById("div_id").setAttribute("ng-click", "function_name()"); $scope.$apply(); Everything looks fine, in the debugger i see that attribute was added but it doesn't execute my function. Do you have any ideas how to add attributes to the existing div and how to make it works? 回答1: You need to recompile your div var el = angular.element("div_id"); $scope = el.scope(); $injector = el.injector(

setAttribute, onClick and cross browser compatibility

喜夏-厌秋 提交于 2019-11-26 14:49:46
问题 I have read a number of posts about this but none with any solid answer. Here is my code: // button creation onew = document.createElement('input'); onew.setAttribute("type", "button"); onew.setAttribute("value", "hosts"); onew.onclick = function(){fnDisplay_Computers("'" + alines[i] + "'"); }; // ie onew.setAttribute("onclick", "fnDisplay_Computers('" + alines[i] + "')"); // mozilla odiv.appendChild(onew); Now, the setAttribute() method (with the mozilla comment) works fine in mozilla but