JQuery | How to get attributes of iframe from other html? [duplicate] - javascript

This question already has answers here:
How can I access the contents of an iframe with JavaScript/jQuery?
(15 answers)
Closed 8 years ago.
I want get the attribute 'src' of a iframe from other html.
I can get the attribute of a iframe in the same html but not from other html,
look my code:
/////////iframe attribute from the same html//////////
var Mframe_src = $("#Mframe").attr('src');
alert(Mframe_src);
//////////iframe attribute from other html////////////
var frame_Ads = $("#Mframe").contents();
var Ads_src = frame_Ads.find("#ads");
alert(Ads_src.attr('src')); /// the alert present me undefined

That's impossible, you could try to get the iframe content by ajax though and then do something with that.
$.get("my iframe page").success(data){
//do something
});

Related

How do i add content in an div with javascript? [duplicate]

This question already has answers here:
How can I change div content with JavaScript?
(6 answers)
Closed 7 years ago.
How do i change the content of an div on an website that has an id with javascript?
<div class="chat-area" id="chat-area">[Changeable]</div>
I want to know how i add content where it says "[Changeable]" with javascript so i can run the command through the console.
I'd like if you keep your explainage simple, because im still very new to html/css/javascript ;)
In very simple JavaScript terms, you can use:
document.getElementById("chat-area").innerHTML = 'New Content';
And yes, this would work in GreaseMonkey / UserScripts too!
You can use the innerHTML property to achieve your goal like so:
document.getElementById("chat-area").innerHTML = "Your new content here";

I want to get the text of an html element and put it in a JavaScript variable [duplicate]

This question already has answers here:
Assign div text to variable then show it
(3 answers)
Closed 8 years ago.
I have the following div:
<div id="mydiv">something</div>
I need to get the content of the div (mydiv) and put it into a JavaScript variable. How can i do it?
var content = document.getElementById("mydiv").innerHTML;

Get div attribute value on page load [duplicate]

This question already has answers here:
How do I check if an element is hidden in jQuery?
(65 answers)
Closed 8 years ago.
I want to get value of div attribute. Like I want to know whether the div is "display:block;" or "display:none" at the time of page load. If "display:block;" then it will be "display:block;" after the page load again if not then "display:none". Can anyone help me with jquery method or code?
Do this:
<script>
$(document).ready(function(){
var x =$("#divId").css("display");
alert(x);
});
</script>

add styles to iframe with javascript [duplicate]

This question already has answers here:
How to apply CSS to iframe?
(28 answers)
Closed 8 years ago.
I'm wanting to update an iframe with css in javascript. I know how to update the iframe body with the code below but is there a way to insert css into the head of the iframe?
Thanks David
var previewFrame = document.getElementById('previewFrame');
var preview = previewFrame.contentDocument || previewFrame.contentWindow.document;
preview.open();
preview.write('New Content');
preview.close();
I think if you have iframe page under the same domain you should try this:
$("iframe").contents().find('head').append('<style type="text/css">' +'MY CSS IS HERE' + '</style>')

Element destination [duplicate]

This question already has answers here:
Retrieve the position (X,Y) of an HTML element
(30 answers)
Closed 9 years ago.
I created a html page and inserted a textbox. I would like to know a textbox destination in the page from javascript function? Example textbox's top is 100 px like that. Thank you.
Try this:
window.onload = function() {
console.log(document.getElementById("id1").offsetTop);
};
where id1 is the id of the textbox you need to triangulate.

Categories

Resources