Get div attribute value on page load [duplicate] - javascript

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>

Related

how to run a function after html value change [duplicate]

This question already has answers here:
jQuery Event : Detect changes to the html/text of a div
(13 answers)
Closed 5 years ago.
I am doing a simple hover scrollbar project. I want to change the height of thumb when someone change the contents in html tag by prepend(),append(),html()..etc. how can I do this? I googled it and found answers like
$('.class').html('value').trigger(somefunction())
But it is not the answer. Because I am not the developer of other js codes. I want to do this with only my script file.
here is my project :-
https://github.com/rameshkithsiri/hoverscroll
Here is way of doing so , you can use DOMSubtreeModified events. But look out It before using it.
$("body").on('DOMSubtreeModified', ".myCLASS", function() {
alert($(this).html());
});
setTimeout(function(){ $(".myCLASS").html("my Test") }, 3000);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="myCLASS"></div>

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

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
});

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 image clicked element with Jquery [duplicate]

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);
});

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