• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can't get jQuery to have effect

 
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, but this doesn't address the path problem I'm having.

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

Thanks.

-- Mike
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Mike London
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where is the js file in relation to the web app root? Starting with the context path, it should be straight-forward.
 
Mike London
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I had a dime for every time I made that kind of mistake...
 
Mike London
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
It sure was nice of your sister to lend us her car. Let's show our appreciation by sharing this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic