Reputation: 352
I am creating an object element dynamically in jQuery, to render some content. It works in all browsers except IE8.
The code:
j$(document).ready(function(){
j$('.objContainer').html(j$('<object>').attr(
{'data':'http://www.stackoverflow.com',
'type':'text/html'}));
});
The HTML structure created after the execution(in IE8):
<object type="text/html"></object>
In other browsers[IE9, Firefox, Chrome]:
<object data="http://www.stackoverflow.com" type="text/html"></object>
Any solutions?
Upvotes: 6
Views: 10058
Reputation: 345
It should work fine, Though i recommend you use $.data() method
http://api.jquery.com/jQuery.data/
It is much safer, and jQuery ensures that the data is removed when DOM elements are removed via jQuery methods.
Example:
<object id='myObj' data-url="http://www.stackoverflow.com" type="text/html"></object>
And you can read the value like:
var url = $('#myObj').data('url');// Read the value
$('#myObj').data('url', 'some-other-value');// Set a new value
Upvotes: 1
Reputation: 12266
Works for me: using the IE8 developer tools, I can see the data attribute. Here's a screenshot.
(I know I shouldn't have to say it, but: you need to make sure that you're allowing scripts to run.)
Upvotes: 3
Reputation:
as you see here, data (dataset) is not supported by IE.
What you can do is rename data to data-foo and then $(..).data("foo")
will work
even in IE because of a special handling by jquery itself.
This is a way to bypass dataset limitation for IE.
Upvotes: 1