BBaysinger
BBaysinger

Reputation: 6987

iterate over properties of HTML element, and be able to tell which are explicitly set in HTML

I'd like to be able to iterate over all of the properties of an HTML element, and be able to tell which ones of those are ones that are explicitly set in the HTML tag. Is there a shortcut way to do that, or will I have to write some custom JavaScript to inspect the element, and look for those properties as strings?

So if I have an element defined in static HTML as:

<source id="some-video" src="some-video.mp4">

And then I set an arbitrary property to it in JavaScript, like:

document.getElementById("some-video").someProperty = "property value";

Is there a shortcut way to iterate all the properties, and be able to know which ones were set through HTML, versus ones that were set via JavaScript (or default properties, added natively).

Upvotes: 0

Views: 39

Answers (1)

Scott Marcus
Scott Marcus

Reputation: 65806

You can iterate over all the properties and attributes, but there's no way to tell what attributes were altered via JavaScript as opposed to set statically unless you kept a record of the element before any changes were made to it.

Upvotes: 2

Related Questions