Click here to Skip to main content
15,895,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
$(document).ready(function() {
    $('.simpleTooltip').hover(function(){
		var hrefval= $(this).attr('href');
		hrefval=hrefval.replace('#','');
        var title =$('a[name="' + hrefval + '"]').parent().parent().text(); //$(this).attr('title');
		if (title.length > 200)
			{
			title = title.substring(0,200);
			title = title + "..........."
			}
        $(this).data('tipText', title).removeAttr('title');
        $('<p class="tooltip"></p>')
        .text(title)
        .appendTo('body')
        .fadeIn('slow');
    }, function() {
        $(this).attr('title', $(this).data('tipText'));
        $('.tooltip').remove();
    }).mousemove(function(e) {
        var mousex = e.pageX + 20;
        var mousey = e.pageY + 20;
        $('.tooltip')
        .css({ top: mousey, left: mousex })
    });
});


the above script is not working without document.ready(). I have a part of the document which is loaded via ajax and hence the page which contains reference to the above script does not reload as the page is not loading.
so how can I make it work?
Posted
Comments
ZurdoDev 19-Feb-15 11:05am    
I'm confused. If you remove the script then you're right, it won't work.
vbmike 19-Feb-15 14:55pm    
If I understand your question correctly, you will want to check out http://api.jquery.com/delegate/ page for some ideas to try out.

1 solution

How? Don't use it "without document.ready()". If you think that document.ready() if always superfluous, you are welcome to try leave without it. I actually do a lot of stuff not handling this event. It depends on what you do. But when you find out the cases you need to handle ready, either use it or use your own mechanism of handling the situation. If you have some real concern, you are very welcome to ask another question.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900