• Resolved borimrr

    (@borimrr)


    I have the following code right before the end of the html head:

    <script type="text/javascript">
    	jQuery(document).ready(function () {
    	jQuery("li:has(ul)").hover(function () {
            jQuery(this).children("a").click(function() {
    	return false;
    	});
    	});
    	});
    </script>
    <script type="text/javascript">
    	jQuery(document).ready(function () {
    	jQuery("h1").click(function(event){
    	jQuery(this).hide("slow");
    	});
    </script>

    The first one works which disables the links on parents with children pages for obvious reasons.

    The second one was me playing around to test my jquery knowledge so far (barely starting). I want it to slowly hide the page title when I click on it which is enclosed in an h1 tag. But it’s not doing it. Any ideas?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter borimrr

    (@borimrr)

    I found the problem. If i put the second script of code for the h1 hide inside the firs script of code’s function call it works. I guess I can’t have ,ore than one function call outside of the same script?

    The second script does not have enough closing brackets/parenthesis.. (that’s probably your intial issue).

    I’d still advise combining the two like you’ve done anyway, why have two scripts seperate if they both fire on document load?

    I’d do it like so.. (which is probably what you have now anyway). Note, a small mod, so you can use $ for your jquery… ??

    <script type="text/javascript">
    jQuery(document).ready(function($) {
    	$("li:has(ul)").hover(function () {
    		$(this).children("a").click(function() {
    			return false;
    		});
    	});
    	$("h1").click(function(event){
    		$(this).hide("slow");
    	});
    });
    </script>

    NOTE: Tabbing code inside parenthesis helps see when you’re missing closing characters, as above. It’s not essential but it’s easier to read and spot errors with appropriate tabbing.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘jQuery not working (already using jQuery instead of $)’ is closed to new replies.