Trouble arises when attempting to include numerous Visualforce components on a single page

When using a visualforce component multiple times on a page, the hover function does not open any of the dialogs. The problem seems to be related to the ids but I'm unsure about how to resolve it.

Below is an example of the code for the visualforce component:

<apex:attribute name="Contents" description="display message" type="string" required="true" assignto="{!DialogMessage}" />
<style>
        .modal {
          display: none; /* Hidden by default */
          position: fixed; /* Stay in place */
          z-index: 1; /* Sit on top */
          padding-top: 100px; /* Location of the box */
          left: 0;
          top: 0;
          width: 100%; /* Full width */
          height: 100%; /* Full height */
          overflow: auto; /* Enable scroll if needed */
          background-color: rgb(0,0,0); /* Fallback color */
          background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
        }
        
        /* Modal Content */
        .modal-content {
          background-color: #fefefe;
          margin: auto;
          padding: 20px;
          border: 1px solid #888;
          width: 80%;
          height: 80px;
          -moz-border-radius: 15px !IMPORTANT;
          border-radius: 15px !IMPORTANT;
        }
        
        /* The Close Button */
        .close {
          color: #aaaaaa;
          float: right;
          font-size: 28px;
          font-weight: bold;
          margin-top: -20px
        }
        
        .close:hover,
        .close:focus {
          color: #000;
          text-decoration: none;
          cursor: pointer;
        }


        a.ActionObject:hover#ModalBox1 {
            display:inline;
        }
        </style>        
        <a id="ActionObject" >        
            <img src="/s.gif" />
        <div id="ModalBox1" class="modal">
            <!-- Modal content -->
            <div class="modal-content">
                <span class="close">&times;</span>
                <p><center>{!DialogMessage}</center></p>
            </div>
        
        </div>
    </a>

The problematic part lies in:
        a.ActionObject:hover#ModalBox1 {
            display:inline;
        }

I've attempted using JavaScript and tried various CSS methods such as using ~, but none have proven successful. If using JavaScript, there needs to be a way for it to identify the correct Id to determine which component to display.

Answer №1

Here are a couple of ideas for you to experiment with.

  1. The selector a.ActionObject:hover#ModalBox1 won't work in this case. You don't have any element with the class "ActionObject," instead, you have an element with the id

    <a id="ActionObject" >
    .

  2. You should examine the generated HTML because Salesforce might be altering your IDs into something like

    j_id0:j_id1:j_id3:j_id58:ModalBox1
    (generated from top, ID of the <apex:page> if present, else auto-generated id. This format includes colons and IDs of subsequent elements in the DOM tree). Check out this link for more information:

  3. Consider using something other than IDs. If you have another unique identifier, you could assign the record's ID as a class or utilize a "data" attribute

  4. Alternatively, there is a special global variable called {!$Component} that allows you to obtain the ID of the correct element. You could use this variable in place of CSS by implementing something like

    <a onmouseover="show('{!$Component}')" onmouseleave="hide('{!$Component}')">

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Header unresponsive to user interactions

Hey everyone! I'm new to using Foundation and I've hit a roadblock in my code on a medium-sized device. I would greatly appreciate your input to help me identify my mistake. Below is the snippet of my code: <div class="row"> <div cl ...

Combine multiple .less files into a single .less file without the need for recompilation

I currently have 3 different .less files (1file.less, 2file.less, 3file.less) that I want to combine into a single file called base.less. To import these files into base.less, I am using the @import "1file.less" method. However, upon inspecting the pa ...

Using Jquery to toggle a class on click, and dynamically change based on the screen size

I am trying to figure out how to toggle a CSS class on an element by clicking on a div using jQuery. I know how to do it, but I also want the toggle to only happen when the screen size is less than 800px. I'm not very familiar with JavaScript, so I co ...

Executing Cascading Style Sheets (CSS) within JQuery/Javascript

I've been encountering a problem with my website. I have implemented grayscale filters on four different images using CSS by creating an .svg file. Now, I'm looking to disable the grayscale filter and show the original colors whenever a user clic ...

Combining a contact form with a Google Map div using the Bootstrap grid system

Hey there, I'm currently facing a challenge with grid placement as I try to position a Google map div next to my contact form. The struggle is real! <div class="container"> <div class="row"> <div ...

jquery's animation causing elements to move abruptly when containing text

For the past hour, I've been grappling with jQuery and could really use some assistance. The following example showcases smooth animations: when you click on either of the divs, the selected div will move left or right if the viewport is wider than 70 ...

Steps for placing an image within the boundary of a rectangular div

My div has a width of approximately 730px and a height of 50px. I am looking to place an image at the bottom of the div, exactly where its height ends - after 50px. I have been considering a query to append the image at the bottom. One solution could be ...

I'm looking to replicate the header design of the classic olx website. Is there anyone who can guide me on how to extend the search bar to match the original image?

Could use some help stretching my search input field to match the original picture. Any tips or suggestions on how to achieve this? I'm utilizing bootstrap and react.js for this project. Uploaded are the original image and my resulting image for compa ...

customizing the appearance of a plugin

Visit the live site here. I am attempting to customize the text displayed in black under the Upcoming Events section. Despite multiple attempts using different combinations such as .vevent-item odd event-1 .description .event-time .event-label, I have not ...

Combining various font files under a single @font-face declaration

Here is the code snippet I'm currently working with: @font-face { font-family: 'icomoon'; src:url('../fonts/icons/icomoon.eot?2hq9os'); src:url('../fonts/icons/icomoon.eot?#iefix2hq9os') format('embedded-opent ...

Google/StackExchange Menu Tab

I am interested in creating a navigation bar similar to Google's or StackExchange's new one, where it is always positioned at the top. It does not need to be fixed there, but I would like it to have links only. How can I achieve this layout with ...

How can I address the issue of width:100% truncating the content and causing a horizontal scrollbar in HTML/CSS?

I've searched high and low for a solution to this issue but have come up empty-handed every time. It's possible I just didn't search hard enough, but everything I've attempted so far has failed to work. This problem has been plaguing me ...

Interactive website that transitions to a fresh page as we scroll further

As a beginner in web design, I've noticed a trend of companies using websites that automatically transition to the next page when scrolling down. An example of this is . What is this type of template called and are there any open source designs availa ...

Stop the border from curving along with the container's border radius

Currently, I am working on a tabs component that features a container with border radius. When a tab item is selected, it should display a bottom border. However, I'm facing an issue where the border curves along with the border radius instead of rem ...

"Utilize jQuery to create a dynamic animation by togg

Looking for guidance on how to add animation to gradually reveal the answer? Provided my code below. Any assistance in making this functional would be greatly appreciated. <div class="q-a-set"> <div class="licensing-question" id="q_1"> <i ...

A guide on updating progress bar value based on user input

I have an input field and a progress bar that needs to be updated based on the input. The task is to input a number (%) and then display that value in the progress bar upon clicking the "Apply" button (btn-primary). Below is the HTML code provided: < ...

Switching the navigation drop down from hover to click: A step-by-step guide

I'm currently designing a responsive navigation bar with a dropdown feature that expands on hover. However, I've encountered an issue as this hover effect is not ideal for mobile devices. Therefore, I am looking to modify my navigation bar so tha ...

Combining Three.js with iFrame for a mix of WebGL and CSS3D

After some experimentation, I successfully created a dynamic page that seamlessly integrates WebGL and CSS3D (with valuable guidance from this helpful SO post). To add an extra touch, I included an iframe: However, I noticed that the functionality to inte ...

Align text to the right and left side

HTML file: <div id="home"> <b><p class="split-para">java<br><a href="j_temp.html" class="float">temperature converter in terminal</a> <br> <a href="j_palindrom.html" class="float">palindrome checker</a& ...

Tips for aligning divs in Zurb Foundation 3 framework

My design conundrum involves a 12 column row and trying to make a series of four div blocks stay in a row without stacking as the browser size decreases. Currently, the divs start to stack when the browser gets smaller. I have 4 divs that should be displa ...