jQuery.wrap()
Blogs20112011-02-17
While my php+js codes with jQuery.wrap() function work fine in FF and Chrome, they donât work at IE.
The following are the issue and solution of jQuery .wrap() in IE:
The codes are: 1. totally 2 type of elements: a image, and multi-checkbox. 2. orginally, the image is without a link. 3. when user select checkbox(es), this image is wraped with a link, to present checkbox is selected, and the image becomes clickable. 4. if un-select the checkbox, the image is unwrap.
5. The html codes:
âŠ
4. The jQuery codes (in App package):
count_deleted : function() {
total = $("input[name='deleted']:checked").length;
if(total>0) {
if(App.count==0) {
$("#img_delete").wrap('<a href="doSomeAction.php" target="i_view">');
App.count ++;
}
}
else {
// alert($("#img_delete").parent().get(0).tagName);
if($("#img_delete").parent().is('a')) {
$("#img_delete").unwrap();
App.count = 0;
}
}
return true;
}The js doesnât work in IE. No link appears, and no further action.
I spent some time ad finally found out the solution: IE needs html tag closed, like the following:
$("#img_delete").wrap('<a href="doSomeAction.php" target="i_view"></a>');`
The is very important here, the closing tag is that ONLY requirement for IE to work flawlessly. Without the closing tag it will not work.
I noticed even in jQuery official webpage: http://api.jquery.com/wrap/ there is no such case. IE follows strictly with DHTML, otherwise it wonât work. Is it good or not?`
