0

This might be a simple question, but I got confused here.

var videoSrc = "video/sample.mp4";
$('.abc').append('<video width="650" height="300" controls="controls"> <source src= "' 
+ videoSrc 
+ 'type="video/mp4" id="myVideo"/>Your browser does not support the video tag.</video>'     
);
});

I am trying to insert the value of the variable videoSrc in the src attribute. It does not work like this.

The following code works fine:

$('.abc').append('<video width="650" height="300" controls="controls"> <source src="videos/sample2.mp4" '
+'type="video/mp4" id="myVideo"/>Your browser does not support the video tag.</video>'      
);

But I have to insert the value of src attribute dynamically.

Help me to fix this.

Thanks

3 Answers 3

3

You haven't got a closing quote for your src attribute, and as @Luuk van Egeraat points out, you have a superfluous "});" at the end.

var videoSrc = "video/sample.mp4";
$('.abc').append('<video width="650" height="300" controls="controls"> <source src= "' 
+ videoSrc 
+ 'type="video/mp4" id="myVideo"/>Your browser does not support the video tag.</video>'     
);

becomes

var videoSrc = "video/sample.mp4";
$('.abc').append('<video width="650" height="300" controls="controls"> <source src= "' 
+ videoSrc 
+ '" type="video/mp4" id="myVideo"/>Your browser does not support the video tag.</video>'     
);
Sign up to request clarification or add additional context in comments.

Comments

1

Just some syntax errors, here is a working version.

var videoSrc = "video/sample.mp4";

$('.abc').append('<video width="650" height="300" controls="controls"><source src= "' + videoSrc + '" type="video/mp4" id="myVideo"/>Your browser does not support the video tag.</video>');​  

2 Comments

The code is valid, the file, however, is not there, so nothing will play.
Hi Luuk, ya I know what you saying. Thanks for the quick help.
0

This one worked:

var videoSrc = "video/sample.mp4";
$('.abc').append('<video width="650" height="300" controls="controls"> <source src= " ' 
+ vidSrc 
+ ' " type="video/mp4" id="myVideo"/>Your browser does not support the video tag.</video>'     
);

Thanks everyone.

Comments

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.