0

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 ?

3
  • what do you mean by the value of the element? Commented Apr 29, 2018 at 8:04
  • @Mamun the element is a textfiled so in normal textfield we can use something like textfield.value = "bla bla bla" , but here it is a different story Commented Apr 29, 2018 at 8:05
  • "Use this element to embed multimedia (like audio, video, Java applets, ActiveX, PDF, and Flash) in your web pages." w3schools Commented Apr 29, 2018 at 8:07

2 Answers 2

2

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>

Sign up to request clarification or add additional context in comments.

6 Comments

I get the error object does not support this property or method
I have tried to use document.getElementById and I was able to get the object my only problem is that when I tried to use getAttribute('data') it returned the error : t is null or not an object where t is the variable I used to store the get by id result
I get this error : document.getElementById(...) is null or not an object
@keloa, update the question with your full code...may be your code is running before the DOM loaded.
@keloa, please place your JavaScript code document.getElementById(........ at the bottom of your HTML body.....OR wrap your code with document.addEventListener...... like I did...
|
1

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();

1 Comment

I get this error : Object does not support this property or method

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.