Tag Archives: iframe

Set the src attribute of the iframe element using jQuery

The following code snippet shows that how you can set the src attribute of the iframe element using jQuery. In the example set the src attribute of the iframe on the click of the submit button.

<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript">
$(function(){
    $("#btnSubmit").click(function(){
      $('#iframWelcome').attr('src', 'welcome.html');
    });
});
</script>
</head>
<body>
<form>
 Enter the name: 
 <input type="text" id="txtName" >
<input type="button" id="btnSubmit" value="Submit" />
<iframe id="iframWelcome">
</iframe>
</form>
 
</body>
</html>

To set the alt attribute, simply pass the name of the attribute ‘src‘ and its value to the .attr() method of the iframe element selector in jquery.

Get the element of the parent window from the iframe in jQuery

The following code snippets will show that how you can access an element of the parent window from the iframe document. The first html document has a input text type control, one button type input control and iframe element. We need to assign value of input text control in the span which are in iframe document using jQuery. Continue reading Get the element of the parent window from the iframe in jQuery