Bug Tracker

Modify

Ticket #3893 (closed bug: invalid)

Opened 4 years ago

Last modified 19 months ago

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:
Blocking: Blocked by:

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

comment:1 Changed 4 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 4 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 4 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to invalid

Works as documented.

comment:4 Changed 19 months 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); 

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.