Reputation: 1
I am really having trouble using the append() function with IE.
What I am trying to do is the following:
Remove the anchor tag afterwards
if($('a#' + id).length == 0){
$('body').append('<a id=\"' + id + '\" href=\"' + gJsAppBasePath + url + '\" class=\"iframe\" title=\"' + title + '\"><\a>');
$('a#' + id).fancybox({
'hideOnContentClick': false,
width: width,
height: height
});
}
$('a#' + id).click();
$('a#' + id).remove();
As expected it works fine in Chrome, FF and Opera, but it doesn't in IE.
What I have already tried to solve this issue:
<a href="../index.html> </a>
<h2>BlaBla</h2>
The anchor tag never is initialized to a proper jQuery object. The h2 tag is, but it won't be shown on the page.
I have found a workaround to hardcode the anchor tag and modify the attributes, but this is not really what I want. Any ideas are very much appreciated.
Thank you in advance, Sebastian
Upvotes: 0
Views: 806
Reputation: 207527
I would expect your code to look more like this:
var anchor = $('#' + id);
if(anchor.length === 0){
anchor = $('<a id=\"' + id + '\" href=\"' + gJsAppBasePath + url + '\" class=\"iframe\" title=\"' + title + '\"><\a>');
$('body').append( anchor );
anchor.fancybox({
'hideOnContentClick': false,
width: width,
height: height
});
}
anchor.click().remove();
Using selectors like element#id
are a lot slower than just doing #id
. Plus in certain versions of IE, it seems to have issues.
Also $('a#' + id)
is expensive and you do it multiple times. There is no need to do it time and time again. You just need to do it once and reuse it wither by variables or chaining.
Upvotes: 1