aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Can't get jQuery to have effect Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Can Watch "Can New topic
Author

Can't get jQuery to have effect

Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1034
Perhaps this shows my newness to jQuery, but, like JavaScript, it seems difficult to get the paths set up correctly initially so that anything happens.

I have a JSP with the following paths in the head tag:


<script language="JavaScript" type="text/JavaScript"></script>
<script src="./jquery.js" type="text/javascript"></script>
<script src="./functions.js" type="text/javascript"></script>

<link rel="stylesheet" href="./test.css" type="text/css" media="screen" />

-------------

And, in the same directory, per the paths above, I have jquery.js, functions.js, and test.css.

Here are the contents of those (except for jquery.js) files:

test.css

#mainText { display: none; }

.title {
font-size: 2.5 em;
font-style: italic;
}

(the JSP file has both a div called mainText and a div id called title)
------------------------

functions.js

$(document).ready(function() {
$('#mainText').fadeIn('2000');
});

--------------------------

Any ideas why jQuery isn't doing anything? Probably simple mistake...

Thanks in advance.

Mike
Rory Slegtenhorst
Greenhorn

Joined: Apr 16, 2008
Posts: 10
Mike,

Try this:


Note that the "./" isn't neccesary if the js is next to the html.
Also note that you need the display style on the tag itself!

Hope this helps,
Rory
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1034
Thanks, but this doesn't address the path problem I'm having.

Also, I named my jQuery file just jquery.js.

Thanks.

-- Mike
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

In a web application, it's a really bad idea to use page-relative URLs. Chances are, they are not addressing what you think they are since the URLs don;t generally reflect real forlders but are servlet mappings.

See the JSP FAQ on resource URLs to learn how to create proper server-relative URLs to your JavaScript files and other images.

P.S. One quick way to find out if jQuery is loaded is to do: alert(jQuery). And see what you get.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1034
Hi Bear,

Thanks as always for your reply.

I thought I was using the relative paths like an example you sent me a week or so back.

In any case, I have another problem since using the context path (from the FAQ you mentioned) has the same problem (can't find jQuery).

And just using the file name itself with no leading path (.\ or anything else) has the same problem too.

Hmmmmmm......

-- Mike
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

Where is the js file in relation to the web app root? Starting with the context path, it should be straight-forward.
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1034
Hi Bear,

The problem turned out to be snytax, not paths.

I had a "." where I needed a "#" in the CSS (the JSP had an id not a class defined).

Thanks for your reply.

- Mike
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

If I had a dime for every time I made that kind of mistake...
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1034
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can't get jQuery to have effect
 
Similar Threads
Adding jquery to a page
Selected row highlighted only for split second
JQuery fade problems
Speed up Application Created USing Servlets and JSP
problem when integrating jspell with tinyMCE editor