'). Attr ('type', 'button') I am trying to create a button using jquery. I am using the following code ...">

IE 7 doesn't like jquery ('<button / ">'). Attr ('type', 'button')

I am trying to create a button using jquery. I am using the following code

jquery('<button/>', {type:'button'}).text(name)

However, this works in Safari, FF IE8, but not in IE7

I tried using the attr function:

jquery('<button/>').attr('type','button').text(name)

this doesn't work either.

what ideas will work? I suppose that if I don’t assign a type, there will be a button by default, but I would rather do it

thanks for the help

+5
source share
3 answers

Try the following:

var button = $('<button type="button"/>');

, , "button" IE ( , 7, 8). . . IE , , jQuery DOM API.

, FF Chrome .


edit β€” , ? jQuery 1.4.4 jQuery 1.5.x. , jQuery 1.6, , , OP: "type" , jQuery.

, , , ".setAttribute()" . :

var b = $('<button/>');
b[0].setAttribute('type', 'button');

, "type". ( , Microsoft "" ".) 1.6 . " " , DOM, , DOM. 1.6 ".setAttribute()", "", ( ) .

+5

:

var $btn = $("<button>Button Text</button>");

. , DOM, .

+1
-1
source