I am trying to make the links not do the default action as going to the link, instead when user clicks the link it does the rest of the code which, in this case loads the appropriate url elements that I am calling with AJAX and place them in the correct Divs/span. Here is the code…
$(function(){
$('body').append('<span id="view_mess">New Message</span><div id="mess_wrapper"><div id="new_mess_pop"><div id="button_wrap"><span id="post_date_time"></span><div id="users_contact_info"><div id="users_image"></div><div id="message_lister"></div></div><div id="message_post"></div><div id="inner_mess_wrapper"></div></div></div></div>');
$('#message_lister').load('/privmsg?folder=inbox .tdtopics:lt(5)');
$('#view_mess').click(function() {
$('#mess_wrapper').show();
});
$('.topictitle').click(function(e) {
var msg = $('.tdtopics a').attr('href');
$.get(msg, function (data) {
var elems = $(data);
$('#post_date_time').append(elems.find('div.posthead h2'));
$('#users_image').append(elems.find('.user-basic-info'));
$('#message_post').append(elems.find('.entry-content'));
}, 'html');
e.preventDefault();
$('#mess_wrapper').show();
});
I’ve tried e.preventDefault(); where it is in the above code and right after the function code. Maybe I should write the e in the first function?
1 Answer