Utherr12 Posted February 2, 2011 Share Posted February 2, 2011 var brk = document.createElement('<br />'); This is where javascript console in Chromium triggers the uncaught error.I also have another piece of code like that, and wish to know if it's correct: field = document.createElement('<input name="q"'+i+' type="text" size="50" \>'); If necessary I can supply the whole function (it's not big). I've seen an example for createElement/appendChild usage ... and I followed the example as seen there, but it looks like it's not good.The exact error message is: "Uncaught Error: INVALID_CHARACTER_ERR: DOM Exception 5" Link to comment Share on other sites More sharing options...
justsomeguy Posted February 2, 2011 Share Posted February 2, 2011 It should just be this:document.createElement('br');You just use the tag name, no other markup.e.g.: var el = document.createElement('input');el.setAttribute('type', 'text');el.setAttribute('size', 50); Link to comment Share on other sites More sharing options...
Utherr12 Posted February 2, 2011 Author Share Posted February 2, 2011 OK, thanks a lot, i was wondering if there's a simpler way to add attributes other than get element by tag name with index 0 then element.type = "text", element.value = 6; etc Link to comment Share on other sites More sharing options...
Fmdpa Posted February 2, 2011 Share Posted February 2, 2011 Some element nodes have settable properties like "element.value", "element.alt", etc. If the node does not have a settable property, then you can use the "setAttribute" method. jQuery has a method that simplifies this. $("element").attr({ type: "text", title: "jQuery", value: "value" }); Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.