$("#my_iframe").attr("src","www.examples.com?x=asd&y=qwe");

This is done using jquery while I have to perform this operation without jquery. How to implement this with javascript?

Popo's user avatar

Popo

2,4606 gold badges36 silver badges58 bronze badges

asked Mar 9, 2014 at 16:46

Subham93's user avatar

document.getElementById('my_iframe').src = 'www.examples.com?x=asd&y=awe';

The DOM API provided by the browser gives you things that look like objects with ordinary properties. They're not "ordinary" properties, of course, because magic things happen when you set them (well some of them).

With "modern" versions of jQuery, in a situation like this it's (a little bit) better to use .prop() instead of .attr().

answered Mar 9, 2014 at 16:47

Pointy's user avatar

document.getElementById("my_iframe").src = "www.examples.com?x=asd&y=awe";

or

document.getElementById("my_iframe").setAttribute("src","www.examples.com?x=asd&y=awe");

answered Mar 9, 2014 at 16:48

Tushar Gupta - curioustushar's user avatar

You can use the setAttribute() method to set particular attribute on particular element. like

document.getElementById('my_iframe').setAttribute('src', 'www.examples.com?x=asd&y=awe');

answered Mar 9, 2014 at 16:48

Suman Bogati's user avatar

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.