code_junkie

How to bind a click event on a recently added <a> tag in jquery

Nov 12th, 2011
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. $(".storyplayer a").bind("click", function() {
  2.  
  3. // replace the <a> tag from the previous media player installation
  4. if (previousplayerlocation != null) {$("#" + previousplayerlocation + " .storyplayer").html(graboldcode);}
  5.  
  6. // now remember this installation's <a> tag before it's replaced
  7. graboldcode = $(this).parent().html();
  8. // remember where I grabbed this <a> tag from
  9. previousplayerlocation = $(this).parents("div.storylisting").attr("id");
  10.  
  11. // replaces the <a> tag with the media player.
  12. $(this).media({width: 190,height: 30});
  13. return false;
  14. });
  15.  
  16. $('#someContainer').click( function(ev){
  17.  
  18. var $el=$(ev.target);
  19. if ( $el.is('a') ){
  20. //do your stuff
  21. }
  22.  
  23. });
  24.  
  25. function playerClicked() {
  26. // replace the <a> tag from the previous media player installation
  27. if (previousplayerlocation != null) {
  28. $("#" + previousplayerlocation + " .storyplayer")
  29. .html(graboldcode)
  30. .click(playerClicked); // Re-add the onclick handler
  31. }
  32.  
  33. // now remember this installation's <a> tag before it's replaced
  34. graboldcode = $(this).parent().html();
  35. // remember where I grabbed this <a> tag from
  36. previousplayerlocation = $(this).parents("div.storylisting").attr("id");
  37.  
  38. // replaces the <a> tag with the media player.
  39. $(this).media({width: 190,height: 30});
  40. return false;
  41. }
  42.  
  43. $(".storyplayer a").bind("click", playerClicked);
  44.  
  45. $('a').livequery('click', function(){
  46.  
  47. });
  48.  
  49. $.livequery.run()
  50.  
  51. $('a').livequery.expire('click')
  52.  
  53. $('a').livequery(
  54. function(){ onmatchHandler},
  55. function(){ onmismatchHandler }
  56. );
Add Comment
Please, Sign In to add comment