user1515425
user1515425

Reputation: 31

Get attributes of a div using javascript

i want to get these value "xxxxx" from the element "src" from these div

i tried so many getelements but it didn't work.

can anybody help me in that

<div id="iframe_container" >
    <iframe name="I1" marginwidth="1" marginheight="1" width="100%" height="100%" frameborder="0" scrolling="auto" align="center" src="xxxxx"  class="floating_iframe"> 
        Your browser does not support inline frames or is currently configured not to display inline frames.
    </iframe>
</div>

Upvotes: 0

Views: 109

Answers (3)

valentinas
valentinas

Reputation: 4337

You need to:

  1. Get the element - in this case iframe (you can use document.getElementById, document.getElementsByName or any of other ways - depends if you're using any frameworks and what markup you have)
  2. once you have the element you can simply call getAttribute("src") on that elemnt.

Example ( http://jsfiddle.net/K3pEw/12/ ):

var iFrame = document.getElementsByName('I1');
alert("The src attribute of your iframe is: "  + iFrame[0].getAttribute('src'))

Upvotes: 0

Scotty
Scotty

Reputation: 2510

If you have access to jQuery, you can write:

var src = $('#iframe_container iframe').attr('src');

Upvotes: 0

jfriend00
jfriend00

Reputation: 707248

If what you're trying to do is to get the src of the iframe, you can use this code:

var iframes = document.getElementById("iframe_container").getElementsByTagName("iframe");
var src = iframes[0].src;

Upvotes: 1

Related Questions