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.
Related
This question already has answers here:
why javascript this.style[property] return an empty string? [duplicate]
(2 answers)
Closed 6 years ago.
I've been trying to get a fade in and out for a background image for a site, and I have been trying to get the background color of a div into a variable, this is what I've tried:
elem = document.getElementById('nav');
bgColor = elem.style.backgroundColor;
But once I try to alert the variable bgColor like: alert(bgColor) all I get alerted is empty in the text box. I've looked around on some Stack questions and I've tried everything that is told there and it doesn't seem to put the physical color into a variable.
window.getComputedStyle is the solution. Otherwise you'll get the "direct" styles that are empty.
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
});
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;
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>
This question already has answers here:
Get selected element's outer HTML
(30 answers)
Closed 9 years ago.
I want to be able to get ANY element's html code when I click on it.
So far I can only get text elements but I can't get image elements.
Here's what I have :
$(document).click(function(event) {
alert($(event.target).html());
});
this doesn't work with images tags like
<img src="" alt=""/>
but only with text ..
Can you please tell me how to proceed to get the images element ?
Thanks in advance.
I think you need to use outerHTML as fields like image/input(self closing) does not contain html
$(document).click(function(event) {
alert(event.target.outerHTML);
});