0

I have a question, I am stumped as to why my code isnt working, I am trying to load a PHP file into a div upon click of a list item anchor tag.

Code:

<script type="text/javascript">
$(document).ready(function() {


//I have these 2 functions aswell that DO work

 $(".itm1 a").click(function(evt) {
     var page = $(this).attr('href');
     $("#page1").load(page);
     evt.preventDefault();
  });

  $(".footnav a").click(function(evt) {
     var page3 = $(this).attr('href');
     $("#page1").load(page3);
     evt.preventDefault();
  });
// ---------------------------

  $(".needslist a").click(function(evt) {
     var page4 = $(this).attr('rel');
     $("#page1").load(page4)
     evt.preventDefault();
  });



});
</script>


<ul>
 <li class="needslist"><span><a rel="/ceos.php" href="#">Are you a CEO SPEECH-MAKER or ENTREPRENEURIAL VISIONARY?</a></span><br />
            who wants the best advice and counsel from an expert coach for your own speeches and leadership events that include speaking to investors, stakeholders, business collaborators, board of directors, conferences and/or the media?</li><br />

 </ul>

Can anyone offer an explination to why its not working?

EDIT: Okay Guys, So I found out once I load a div by ajax, that content becomes unable to process jquery. This is my problem.... How do I execute jquery scripts on loaded content????!!!

onei0120
  • 189
  • 1
  • 9
  • 28

1 Answers1

1

Found a solution:

Once you load ajax content, you cant execute any scripts on that loaded content, heres my solution:

$(".needslist a").live("click", function(evt) {
     var page4 = $(this).attr('rel');
     $("#page1").load(page4);
     evt.preventDefault();
  });
onei0120
  • 189
  • 1
  • 9
  • 28
  • Using `live()` is not recommended it has many drawbacks and issues. Use `on()` which is the recommended method since jQuery 1.7 or use `delegate()` pre 1.7 for binding to dynamic elements and `bind()` for static elements. See jQuery documentation on `live()` for a list of the issues: http://api.jquery.com/live/ – Nope Aug 24 '12 at 09:19