[jQuery] $('<a>').size() === 0 in IE??
I'm going to explain my problem by code. Both of these work perfectly
fine in Firefox but only the *second one* works in IE 6.
** THE ONE I WANTED TO WRITE **
function __duplicateToolbarButtons() {
// Make "save" and "save and view" buttons appear in toolbar
if ($('#CMSButtonBar').size() && $
('input.duplicateintoolbar').size()) {
// Next, make <A> elements then put them into button bar
$('input.duplicateintoolbar').each(function() {
var btn = this;
var a = $("<a>")
.attr('href','#')
.addClass('ButtonAction')
.click(function() {
btn.click(); return false
})
.text(btn.value);
// insert it just before the last <div> in that area
$('div', $('#CMSButtonBar')).slice(-1).before(a);
});
}
}
** THE ONE I HAD TO WRITE **
function __duplicateToolbarButtons() {
// Make "save" and "save and view" buttons appear in toolbar
if ($('#CMSButtonBar').size() && $
('input.duplicateintoolbar').size()) {
// Next, make <A> elements that put them into button bar
$('input.duplicateintoolbar').each(function() {
var btn = this;
var a = document.createElement('a');
a.setAttribute('href','#');
a.className='ButtonAction'; //
a.setAttribute('class','ButtonAction') doesn't work
a.onclick=function() {btn.click(); return false};
a.innerHTML=btn.value;
// insert it just before the last <div> in that area
$('div', $('#CMSButtonBar')).slice(-1).before(a);
});
}
}
At first I thought it was something wrong with the way I appended the
created element into the DOM tree but then I added this code just
after the $('<a>')... stuff::
alert(a.size());
In Firefox it said 1 (as expected) but in IE 6 it said 0!! Why?
Are there pitfalls I don't know about in creating elements in IE that
are FAQ?
PS. This is jquery-1.2.3.min.js and the piece of junk is IE 6.0 sp2.