tags:

views:

78

answers:

4

Hello,

when I click on "Click Here" then a page must open inside

<script....>
$('yahoo').html('<a href=desc.php>');
</script>

<div id='yahoo'></div>
<div id='clickhere'>Click here</div>

Thanks Dave

+5  A: 

I think you're looking for AJAX to fetch the page for you. Something like this might work:

<script type="text/javascript">
    $(function() {
        $('#clickhere').click(function() {
            $('#yahoo').load('desc.php');
        });
    });
</script>

<div id='yahoo'></div>
<div id='clickhere'>Click here</div>

First you need to wrap the script inside $(function() { ... }) to execute your code on page load. This is equivalent to $(document).ready(function() { ... }).

Next you have to bind a click event to the #clickhere element so you can actually do something when the user clicks on it.

When the user clicks on the #clickhere div, load() will fetch the contents of the given url inside the element you call it from. So, this snippet means that when the #clickhere div is clicked, desc.php is loaded inside #yahoo div.

Tatu Ulmanen
+1 for being fast and thorough .
Gaby
thanks it worked
Jean
yes guys i know i have to wrap...
Jean
+1  A: 

Wrap your code in $(document).ready(function() { });, which will insure that the code executes after the DOM is available to your code. Otherwise, $('yahoo') will likely return no matched elements.

meagar
+2  A: 
  1. ID selector is #ID, not just ID
  2. Use jQuery AJAX load method to load desc.php page
  3. You should execute your jQuery code after DOMContentLoaded event
Crozin
A: 

Why not try target_self ? I also fixed some code

<script....>
$('yahoo').html('<a href=desc.php target='>self'>Click here</a>');
</script>

<div id='yahoo'></div>
<div id='clickhere'>Click here</div>
streetparade