Jump to content
pstein

How to remove attributes?

Recommended Posts

Assume I have the following HTML source code:

 

<img onload="..." ... someotherattr="..." ...> ... </img>

 

How can I remove the two attributes "onload" and/or "someotherattr" but not all other (possibly existing) attributes?

 

Can I put the remove command for the two attributes into one statement or do I have to setup two commands (for one attribute per command)?

 

jQuery can be used if it is simpler

 

Thank you

Peter

 

Share this post


Link to post
Share on other sites

Remove these from html element manually would be the easier option, as you need element to exist to target and remove attributes, but! on rendering the elements onload event would kick in anyway, so you would lose that battle to remove onload attribute before it is triggeted.

Share this post


Link to post
Share on other sites

Yes! But if element has onload attribute in which you want to remove to prevent it being triggered, the onload will be triggered before a removeAttribute() has a chance to be initiated. The element has to be rendered first before a attempt to remove attribute can attempted, but! If element is rendered the onload is triggered.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×