• 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
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

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: 67257
170
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.
  •  
    Saloon Keeper
    Posts: 20658
    122
    Android Eclipse IDE Java Linux Redhat Tomcat Server
    • 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: 4042
    47
    • 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!
     
    Roses are red, violets are blue. Some poems rhyme and some don't. And some poems are a tiny ad.
    ScroogeXHTML - the small and fast RTF to HTML converter library
    https://coderanch.com/t/707504/ScroogeXHTML-RTF-HTML-XHTML-converter
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!