Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 8 years ago

#3893 closed bug (invalid)

IE doesn't create elements using $('<tag>') syntax

Reported by: marioestrada Owned by:
Priority: major Milestone: 1.3.1
Component: core Version: 1.3
Keywords: Cc:
Blocked by: Blocking:

Description

jQuery in IE is not creating the html elements that are being appended to dynamically created elements, both using the $('<tag>') syntax.

This code doesn't work in IE:


paginador = $('<div>').attr('class', 'paginador'); $('.pagina:eq(0)').before(paginador); btn_fwd = $('<a>').attr({'id': 'btn_fwd', 'href': '#', 'class': 'btn'}).text('>>'); btn_rew = $('<a>').attr({'id': 'btn_rew', 'href': '#', 'class': 'btn'}).text('<<'); paginador.append(btn_rew); paginador.append(btn_fwd);


This results in IE7 creating the <div> element, but not creating/appending the <a> elements.

To go around this I used:


paginador = $('<div>').attr('class', 'paginador'); $('.pagina:eq(0)').before(paginador); btn_fwd = $(document.createElement('a')).attr({'id': 'btn_fwd', 'href': '#', 'class': 'btn'}).text('>>'); btn_rew = $(document.createElement('a')).attr({'id': 'btn_rew', 'href': '#', 'class': 'btn'}).text('<<'); paginador.append(btn_rew); paginador.append(btn_fwd);


And it worked as expected.

Change History (4)

comment:1 Changed 11 years ago by marioestrada

doesn't work:

paginador = $('<div>').attr('class', 'paginador');
$('.pagina:eq(0)').before(paginador);
btn_fwd = $('<a>').attr({'id': 'btn_fwd', 'href': '#', 'class': 'btn'}).text('>>');
btn_rew = $('<a>').attr({'id': 'btn_rew', 'href': '#', 'class': 'btn'}).text('<<');
paginador.append(btn_rew);
paginador.append(btn_fwd); 

works:

paginador = $('<div>').attr('class', 'paginador');
$('.pagina:eq(0)').before(paginador);
btn_fwd = $(document.createElement('a')).attr({'id': 'btn_fwd', 'href': '#', 'class': 'btn'}).text('>>');
btn_rew = $(document.createElement('a')).attr({'id': 'btn_rew', 'href': '#', 'class': 'btn'}).text('<<');
paginador.append(btn_rew);
paginador.append(btn_fwd); 

sorry for not formatting the first time...

comment:2 Changed 11 years ago by balazs.endresz

http://docs.jquery.com/Core/jQuery#htmlownerDocument

"When creating single elements use the closing tag or XHTML format. For example, to create a span use $("<span/>")."

comment:3 Changed 11 years ago by dmethvin

Resolution: invalid
Status: newclosed

Works as documented.

comment:4 Changed 8 years ago by anonymous

had the same problem, I had to use var before the variables containing DOM.

var paginador = $('<div />').attr('class', 'paginador');
$('.pagina:eq(0)').before(paginador);
var btn_fwd = $('<a/>').attr({'id': 'btn_fwd', 'href': '#', 'class': 'btn'}).text('>>');
var btn_rew = $('<a/>').attr({'id': 'btn_rew', 'href': '#', 'class': 'btn'}).text('<<');
paginador.append(btn_rew);
paginador.append(btn_fwd); 
Note: See TracTickets for help on using tickets.