简体   繁体   中英

how to edit <object> in javascript

I am editing a system and I noticed a weird tag <object> I tried to search for it but didn't get any luck. the code looks something like this : <object width="50" height="10" tabIndex="12345" id="test" classid="ghjkl" />

so what I need to do is I need to edit the value of this textbox but I didn't get any luck with that. I have tried to grab it by id (and it worked) but I couldn't get the exact value or edit it's value. any ideas ?

The HTML <object> element represents an external resource, which can be treated as an image, a nested browsing context, or a resource to be handled by a plugin.

There is no value attribute for <object> element. Please check MDN link for all the available attributes present in <object> .

But there is data attribute which you can modify:

 document.addEventListener('DOMContentLoaded', function(){ document.getElementById('test').setAttribute('data', 'new-movie.swf'); console.log(document.getElementById('test').getAttribute('data')); }, false); 
 <object width="50" height="10" tabIndex="12345" id="test" classid="ghjkl" data="movie.swf" type="application/x-shockwave-flash"></object> 

Hi if you want to get the value from object tag you can use this code.

HTML

<object width="50" height="10" tabIndex="12345" id="test" classid="ghjkl" />

JavaScript

var t=document.querySelector("#test");
var htmlDocument= t.contentDocument;

If you have jQuery in your project and want to remove the object element you can use the remove method.

$("#test").remove();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM