Win a copy of Spring in Action (5th edition) this week in the Spring 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
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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

 
Greenhorn
Posts: 11
  • 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: 67163
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: 19976
    95
    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()").
     
    Rancher
    Posts: 3748
    40
    • 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!
     
    moose poop looks like football shaped elk poop. About the size of this tiny ad:
    Download Free Java APIs to Work with Office Files and PDF
    htttp://www.e-iceblue.com/free-apis.html
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!