Add object attribute
How can I change the attribute of a tag in some HTML specified as an object?
Currently, if I do this:
console.log(gallery.currItem);
I get:
So I did:
console.log(gallery.currItem.html);
And I am getting HTML in the console (not as an object, I believe it is as texi):
<video width="500" height="250" controls><source src="" type=""></video>
But I'm not sure how to edit the tag video
by adding the attribute muted="muted"
.
I tried:
console.log($(gallery.currItem.html).find('video'));
But this returned the object again.: /
+3
user5140488
source
to share
3 answers
I am assuming you are using PhotoSwipe. gallery.currItem.html
is not a string, but an actual html element. You can simply edit its attributes:
gallery.currItem.html.setAttribute("muted", "muted");
To verify that this is the actual item, if in question, do the following:
if(gallery.currItem.html.tagname) {
gallery.currItem.html.setAttribute("muted", "muted");
} else {
// append it to the dom or wrap it into jquery and then set the attributes
gallery.currItem.html = $(gallery.currItem.html).attr("muted", "muted")[0];
}
+1
Sebastian nette
source
to share
try it.
$(gallery.currItem.html).attr("muted", "muted");
0
jrath
source
to share
Answer:
$(gallery.currItem.container.lastChild).attr('muted', 'muted');
0
user5140488
source
to share