Log in

View Full Version : dynamic script required



sgoyal
08-21-2013, 07:41 PM
1) Script Title: Javascript, JQuery

2) Describe problem: I have made a webpage with jquery with loading header, sidebars, footer and main content window. my site is working ok but i want when someone click a link or form submit in a content div, then the link would open in the same main content div again. I have the js code for a link in sidebars/header to open the same in content div. but do not have if the link is place inside the same div content. Please share the code in any language (PHP, Js, Jquery,etc.).

My code for opening a link of sidebars/header in content div.

<script type="text/javascript">
$('#flat').click(function(){
$('#step2').load('step3layout.php');
});
</script>

Thanks in advance.

jscheuer1
08-21-2013, 09:15 PM
Well, if #flat is a link, you should either return false or prevent the default of the event:


<script type="text/javascript">
$('#flat').click(function(){
$('#step2').load('step3layout.php');
return false;
});
</script>

or:


<script type="text/javascript">
$('#flat').click(function(e){
$('#step2').load('step3layout.php');
e.preventDefault();
});
</script>

And once you do that you can have the href of #flat be the URL you want:


<script type="text/javascript">
$('#flat').click(function(e){
$('#step2').load(this.href);
e.preventDefault();
});
</script>

And once you're doing that, you can do a whole class of links at once:


<script type="text/javascript">
$('.flat').click(function(e){
$('#step2').load(this.href);
e.preventDefault();
});
</script>

And the code will take the href from each link that has a class of "flat".

The browser cache may need to be cleared and/or the page refreshed to see changes.

If you want more help, please include a link to the page on your site that contains the problematic code so we can check it out.