You should use the .setAttribute()
method:
g = document.createElement('div');
g.setAttribute("id", "Div1");
More Related Contents:
- What is Hungarian Notation? [duplicate]
- How can I execute each switch statement case in JS?
- Convert XML to JSON (and back) using Javascript
- How to take screenshot of a div with JavaScript?
- jQuery XML error ‘ No ‘Access-Control-Allow-Origin’ header is present on the requested resource.’
- detect back button click in browser [duplicate]
- Making custom right-click context menus for my web-app
- How to scroll to specific item using jQuery?
- How to run two jQuery animations simultaneously?
- How to get all options of a select using jQuery?
- Get query string parameters url values with jQuery / Javascript (querystring)
- Drop-down box dependent on the option selected in another drop-down box
- jQuery get values of checked checkboxes into array
- How to stop default link click behavior with jQuery
- Displaying pdf from arraybuffer
- jQuery Change event on an element – any way to retain previous value?
- jQuery Mobile : What is the order of page events triggering?
- keep placeholder on focus in IE10
- Emailing to multiple recipients with html Mailto: not working
- jQuery function not binding to newly added dom elements
- Is it possible to append a div inside an SVG element? [duplicate]
- Cancel single image request in html5 browsers
- How to show hidden divs on mouseover?
- Using jQuery inArray with array of JavaScript Objects
- Using .after() to add html closing and open tags
- How do you force your Javascript event to run first, regardless of the order in which the events were added?
- Remove everything within script and style tags
- JQuery AutoComplete, manually select first searched item and bind click [duplicate]
- What does this JavaScript/jQuery syntax mean?
- Google maps responsive resize