Devin Rhode
Devin Rhode

Reputation: 25287

simple javascript question

document.getElementById("myFrame").setAttribute("src") = "http://www.yahoo.com/";

myFrame is an iframe element... when entering this into the chrome developer console, it gives me the error "Invalid left-hand side in assignment" I am trying to update the iframe. Is there a method I am forgetting?

Upvotes: 0

Views: 176

Answers (5)

ChrisNel52
ChrisNel52

Reputation: 15143

Try this...

document.getElementById("myFrame").setAttribute("src","http://www.yahoo.com/");

Upvotes: 0

polarblau
polarblau

Reputation: 17734

You can't assign an function call to something, try this instead:

document.getElementById("myFrame").setAttribute("src", http://www.yahoo.com/");

Upvotes: 1

lonesomeday
lonesomeday

Reputation: 237865

You don't really need setAttribute when setting the src property:

document.getElementById('myFrame').src = 'http://www.yahoo.com/';

Upvotes: 3

glebm
glebm

Reputation: 21090

Here, I fixed it

document.getElementById("myFrame").setAttribute("src", "http://www.yahoo.com/");

Upvotes: 0

Sean Vieira
Sean Vieira

Reputation: 159905

setAttribute takes two arguments:

document.getElementById("myFrame").setAttribute("src", "http://www.yahoo.com/");

You are trying to set the DOM object to the string "http://www.yahoo.com/" ... which is invalid.

Upvotes: 3

Related Questions