Questions tagged [setattribute]
434 questions
                    
                    304
                    
            votes
                
                13 answers
            
        When to use setAttribute vs .attribute= in JavaScript?
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 =…
         
    
    
        Francisc
        
- 77,430
- 63
- 180
- 276
                    83
                    
            votes
                
                3 answers
            
        JavaScript Adding an ID attribute to another created Element
I have some code here that will do the following. The code creates an element "p" then I append it to a "div" in the HTML. I would like that "p" I just created have an unique identifier (ID) and set the name of the ID. So later on when the user…
         
    
    
        king_sw4
        
- 1,125
- 2
- 11
- 18
                    44
                    
            votes
                
                2 answers
            
        Difference between setattr and object manipulation in python/django
I have the following model:
class Ticket(models.Model):
    title = models.CharField()
    merged_to = models.ForeignKey("self", related_name='merger_ticket', null=True, blank=True)
    looser_ticket = models.BooleanField(default=False)
There are…
         
    
    
        whatf
        
- 6,378
- 14
- 49
- 78
                    32
                    
            votes
                
                4 answers
            
        How to Set OnClick attribute with value containing function in ie8?
My goal is to change the onclick attribute of a link. I can do it successfully, but the resulting link doesn't work in ie8. It does work in ff3.
For example, this works in Firefox 3, but not IE8. Why?
         
    
    
        edt
        
- 22,010
- 30
- 83
- 118
                    26
                    
            votes
                
                4 answers
            
        Angularjs dynamically set attribute
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…
         
    
    
        user2282428
        
- 295
- 1
- 3
- 6
                    24
                    
            votes
                
                7 answers
            
        Using request.setAttribute in a JSP page
Is it possible to use request.setAttribute on a JSP page and then on HTML Submit get the same request attribute in the Servlet?
         
    
    
        ria
        
- 7,904
- 11
- 39
- 46
                    18
                    
            votes
                
                3 answers
            
        Correctly adding defer attribute to script tag with pure JavaScript
I am trying to add a deferred script tag like this:
const script = document.createElement('script');
  script.setAttribute('src', '/script.js');
  script.setAttribute('type', 'text/javascript');
  script.setAttribute('defer', true);//this is the…
         
    
    
        ey dee ey em
        
- 7,991
- 14
- 65
- 121
                    17
                    
            votes
                
                3 answers
            
        How to use JavaScript's setattribute to affect multiple elements?
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…
         
    
    
        MathieuB
        
- 505
- 2
- 8
- 20
                    16
                    
            votes
                
                6 answers
            
        Javascript: setAttribute() v.s. element.attribute = value to set "name" attribute
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]); //…
         
    
    
        dkugappi
        
- 2,664
- 5
- 21
- 22
                    15
                    
            votes
                
                6 answers
            
        Simpler way to set attributes with svg?
I'm new to SVG, so I apologize in advance for my ignorance.
I created a fiddle, just playing around with things. http://jsfiddle.net/a46p8/
var svg = document.createElementNS('http://www.w3.org/2000/svg',…
         
    
    
        CRABOLO
        
- 8,605
- 39
- 41
- 68
                    13
                    
            votes
                
                3 answers
            
        How to remove attributes from the NSAttributedString swift?
I have added some attributes to my buttons attributedTitle
 let attr = NSMutableAttributedString(string: currTitle)
 attr.addAttribute(NSStrikethroughStyleAttributeName, value: 2, range: NSMakeRange(0, attr.length))
…
         
    
    
        Salome Tsiramua
        
- 763
- 3
- 9
- 21
                    12
                    
            votes
                
                1 answer
            
        javascript setAttribute style
I don't get how the two following javascript/css codes can produces different result:
1st:
prev.setAttribute('style', 'position:absolute;left:-70px;opacity:0.4;border-radius: 150px;-webkit-border-radius: 150px;-moz-border-radius: 150px;');
2nd:
   …
         
    
    
        user308553
        
- 1,238
- 4
- 18
- 32
                    11
                    
            votes
                
                2 answers
            
        JS - Cannot read property 'setAttribute' of null
I am pretty new to javascript and want to code a header of an html site. 
JS: when the window width is smaller than 1215px --> left part goes 100% width; right part of the header to 0
I always get the "Cannot read property 'setAttribute' of null "…
         
    
    
        karlgustav
        
- 169
- 1
- 3
- 10
                    11
                    
            votes
                
                1 answer
            
        setAttribute and video.src for changing video tag source not working in IE9
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…
         
    
    
        mkralla11
        
- 1,299
- 1
- 13
- 19
                    10
                    
            votes
                
                2 answers
            
        To use getAttribute(), or not to use getAttribute(): that is the question
Possible Duplicate:
JavaScript setAttribute vs .attribute=
javascript dom, how to handle "special properties" as versus attributes? 
Many times, in forums or places such as Usenet I have been told by some (when criticizing my code) that instead of…
        user912695