I have a hyperlink in my jsp.
When we click on this, a popup overlay gets displayed and the background greys out. After closing the popup, the background becomes normal.
Now I want the hyperlink to be clicked automatically when the page loads.
Can anyone say how we can do that?
I tried the following..
$('#ViewOutages').click(); ,
$('#ViewOutages').click();
but none of it worked.. ViewOutages is the div id in which the hyperlink is present.
Can someone please help on this.
window.onload=function(){
if(document.getElementById('test')!=null||document.getElementById('test')!=""){
document.getElementById('test').click();
}
}
This actually worked.. :)
Here you go:
$(document).ready(function() {
$("#ViewOutages").trigger('click');
}
use trigger()
$(function(){
$('#ViewOutages').trigger('click');
})
from
'ViewOutages' is the div id in which the hyperlink is present.
looks like your <a> is inside the div ..i assume you need to use find() or children()
$(function(){
$('#ViewOutages').find('#linkID').trigger('click');
})
Try this,
$(function(){
$('#ViewOutages').find('a').trigger('click');
// if hyperlink is in div#ViewOutages as you said in question
})
You can use $(document).ready(); function which is same as
Related
This is situation: Im making content changing of my page with .load('page.php') function. But my problem is following. When i change content like this , my .click() functions dont work anymore.
Here is my .js code:
$(document).ready(function(){
$(".menu_inner").bind('click',function(){
var product = $(this).attr('prod');
produkt="modules/"+product+".php";
})
$(".menu_list_home").click(function(){
$("#contentwrapper").load('modules/homepage.php');
})
})
It is ok with homepage bind cause div where it is refreshed is not where homebutton is. It is working when page loads. As soon as i click on home, there is nothing to do. It looks like it was unbinded. Any guess?
Martin.
I belive that dom having class menu_inner is also getting changed when you load 'contentwrapper'. Use this:
$(document).on('click', '.menu_inner', function(){
ar product = $(this).attr('prod');
produkt="modules/"+product+".php";
} );
I have a div with text in it and a background image. When I load the page the text always appear 1st(assume i have low speed internet connection). How can i make the background image load before text? Can You please give me solution in both jquery and javascript
Add the text in the onload event handler for the image.
Note: If you want to keep using a div tag with a background image rather than an img tag, you'll have to add the text during the window.onload event (see this answer for the details).
Assuming your div looks like this:
<div id="Derp" style="CSS-for-background-image-here">Magical ponies!</div>
I would try removing the text completely and then add this kind of jquery call:
<script>
$(document).ready(function() {
$('#Derp').load(function() {
$('#Derp').text("Magical ponies!");
});
});
</script>
The $('#Derp').load(...) is the key here. See the docs for load(). It has an example of exactly what you need.
you could populate the content onload.
Start with this:
<div id="content"></div>
Then, in jquery, do this:
$(document).ready(function() {
mybg= new Image();
mybg.onload=function(){
$('#content').html('YOURTEXTHERE');
}
mybg.src = "PATH/TO/IMG";
});
your simple answer is .load you can do when your window gets loaded fully and then text appears:
$(function(){
$(window).load(function() {
$('p').fadeIn(800);
});
});
what this is doing is fading in the p tag with text when whole window gets loaded.
you can find a demo here: http://jsfiddle.net/a5P8b/
First of all, thats my current state of play: thsbrk.de.
The black boxes should be e.g. a about section. I want to achieve that if you enter my page (thsbrk.de) you directly go to my reference section (anchor '#references'). Then, if you hit the about link you will scroll up to that about section. I already tried to make it working but it doesn't. The anchor seems to be not working.
It would be awesome if someone could look at my code and offer me a solution :)
(The scroll isn't implemented yet, I only ask for the anchor problem)
EDIT: Here I've got a example how it should work: Example
Give a script tag like this in the head.Let it be the first script also.
<script>
location.href="http://thsbrk.de/#references"
</script>
From your code, you have did the same. But just try reordering the script tags it might work.
Plain JS:
window.onload=function() {
var anchorHash = 'references';
document.getElementsByName(anchorHash)[0].scrollIntoView();
}
Here is a jQuery example from 2009 - there may be newer ways
How do I scroll a row of a table into view (element.scrollintoView) using jQuery?
In your case this might work
$(document).ready(function() {
var anchorHash = 'references';
var pos = $('#'+anchorHash).position();
window.scrollTo(0,pos.top);
});
Try this and tell me the result:
$(document).ready(function() {
window.location.href = '#references';
});
and then modify your anchor tag like this:
<a name="references">Here</a>
I'm new to jquery and bumped into a problem i can't fix
I want that on pageload my content is sliding down so i use the next code:
$(document).ready(function () {
$("#content").hide();
$("#content").slideDown(1000);
});
when i load the page the content slides down narmally, than the content gets hidden and slides down again.
When i go to the css and do #content{display: none;} instead of $("#content").hide(); everything works fine. (can't use this for browsers without js)
Does anyone know the cause of this?
Thanks!
You are saying that everything works fine while using css #content{display: none;}
than i offer u to use Jquery .css() method( http://api.jquery.com/css/ )..
u can use it like :
$(document).ready(function () {
$("#content").css( { 'display' : 'none' } );
$("#content").slideDown(1000);
});
sipmle as that.
and i also agree with #Billy Moon , it can be a browser specific bug or u may be calling a page refresh command, somewhere within ur code.
Your code has no problem inside. It's somewhere else in your code.
isn't that function call in some function that is called twice?
$(document).ready(function(){
$("a[href*='http://']:not([href*='"+location.hostname+"'])").attr("target","_blank");
$("a[target!='_blank'][target!='_top']").live('click', function(){
$("#actualcontent").html('<center><img src="/deltasite/uploads/smallloader.gif"></center>');
var url=$(this).attr("href")+'?jquery=1';
$("#actualcontent").load(url);
$("#nav").load('/delta/pack_files/other/nav.php?url=' +$(this).attr("href"));
window.location.hash=$(this).attr("href");
return false;
});
});
For some reason, on one embedded page of the site, this seems to affect links and images with onclick attribute. Any idea why? (Even if their target is blank or top). It only seems to do it on one page, annoyingly.
Any ideas?
Thanks,
Tom.
Try excluding images/links which have an onclick attribute, using a combination of the :not selector and the has attribute selector:
$("a[href*='http://']:not([href='foo']):not([onclick])").attr("target","_blank");
Demo: http://jsfiddle.net/HjYEX/2/