Arshad Arsal
Arshad Arsal

Reputation: 115

Add an attribute to an existing element on page load

I have this div on a site, Just need to add a text automatically on page load. So I have tried Jquery append or Jquery text. But it seems they only replacing the content inside the tag.

<video src="how-it-works.mp4" autoplay="autoplay"></video>

I want to add a "controls" text to the video tag. Like below

<video controls src="how-it-works.mp4" autoplay="autoplay"></video>

Any one can help please?

Upvotes: 0

Views: 166

Answers (1)

Frenchy
Frenchy

Reputation: 17027

video is known tag, so have you try:

$("video").prop("controls", true);

or

$("video").attr("controls", "");

if you cant have event to trap if video is here, you could try this:

var timer = setInterval(function() {
    if($("video").length > 0){
       clearInterval(timer);
       $("video").attr("controls", "");
    }
}, 100); 

every 100ms i test if tag video is present

Upvotes: 1

Related Questions