This week's book giveaway is in the XML and Related Technologies forum.
We're giving away four copies of Java XML & JSON and have Jeff Friesen on-line!
See this thread for details.
Win a copy of Java XML & JSON this week in the XML and Related Technologies forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Refer to a div element inside an embedded JSP?  RSS feed

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Having one JSP (main.jsp) that includes another JSP (child.jsp).   In child.jsp there is some <div id="testId" ...>.  In main.jsp, attempt to use jQuery like

$("#testId").xxx  but it seems it doesn't work.. Any idea ?
 
Marshal
Posts: 67224
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JSP-ness is irrelevant once things get to the browser, so it all ends up being one page. So, yes, it should work.

Reasons it might not work:
  • Do you have more than one element with that id? id values must be unique on a page. It's best to avoid them and use class names rather than ids unless you know they are clearly intended to be, and will be, unique.
  • Are you sure that the element exists before this code executes? You could have a race condition.
  •  
    Bartender
    Posts: 20307
    110
    Android Eclipse IDE Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Another reason why it might not work is that "$" is a magic character in the Java Expression Language. When in doubt, don't use "$" as the marker for a jQuery expression, use the long form ("jQuery.xxxx()").
     
    Master Rancher
    Posts: 3887
    45
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    And, when debugging these things, always (always) look at what the browser is actually working with, not the JSP code.
    Use F12 to get at the developer tools and learn how to use the cebugger to follow Javascript flow, the structure part to see what the HTML looks like, and how the styles affect the layout, and the network tab to see what is being sent to the server and what is being received.

    As Bear says, this is not a JSP issue as such.
    It's an issue with the code that lands on the browser, so embrace your browser's dev tools!
     
    All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
    RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
    https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!