JQuery changing data attribute of <object>

2019-08-28 16:40发布

Works perfectly in FF (as you'd expect) but for some reason when I do this:

$('#objectname').attr('data', 'newcontent.php')

...absolutely nothing happens in IE.

When I do an

alert($('#objectname').attr('data', 'newcontent.php')) 

it shows the new data source but doesn't change it...

Any ideas please?

2条回答
Viruses.
2楼-- · 2019-08-28 17:15

We had the same problem. Our solution was to re-set the innerHtml of the parent node. With this (ugly) hack IE picks up the changed data attribute and renders accordingly.

html = val.parentNode.innerHTML;
val.parentNode.innerHTML = html;
查看更多
神经病院院长
3楼-- · 2019-08-28 17:29

I don't think data is a valid HTML attribute. Did you mean to use the jQuery data() function?

$('#objectname').data('name','value');

Update for 9/2014 — This question and answer is over five years old now, and isn't really relevant any more. data is now a valid attribute. I'm leaving my original answer for historical purposes though.

查看更多
登录 后发表回答