SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    Resistance is Futile webgodjj's Avatar
    Join Date
    Nov 2002
    Location
    Madison, WI USA
    Posts
    448
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    onClick() & Load...

    Hi,I'm trying to figure out how to do the following....

    I will have a bunch of links in a div id = "videosLinks".

    I would like an onClick event to send via ajax,load,post, get(whatever) to a file that will receive the data after the query and replace a div with that result... ie
    HTML Code:
    <div id="video">
        Replace Video Here
    </div>
    
    <div id="videoLinks">
      <a href="videoPost.php?Video=GOCTeS5OZp4">Video 1<a>
      <a href="videoPost.php?Video=K4tqzeisltY">Video 2</a>
    ...
    </div>
    Atomic Coffee Media
    http://www.atomiccoffee.com
    JJ Pagac

  2. #2
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    336
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You didn't specify if you were using a library or not, but you could use jQuery for this:
    HTML Code:
    <div id="video"></div>
    
    <div id="videoLinks">
      <a href="videoPost.php?Video=GOCTeS5OZp4">Video 1<a>
      <a href="videoPost.php?Video=K4tqzeisltY">Video 2</a>
    </div>
    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js"></script>
    <script>
    	$(document).ready(function(){
    		$('#videoLinks a').click(function(e) {
    			e.preventDefault();
    			$.get(
    				$(this).attr('href'), 
    				function(data) {
    			  		$('#video').html(data);
    			  	}
    			);
    		});
    	});
    </script>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •