The hidden link inside a span with display: none; style becomes visible

Currently, I am utilizing jquery ui dialog as shown below:

$(document).ready(function() {

    // creating a course
    $('a.openModalBox').click(function(e) {
        var href = $(this).attr('href');
        if ('#/' == href) {
            e.preventDefault();
            $('span.modalBoxContent').dialog({
                modal: true,
                resizable: false,
                title: 'Notification',
                zIndex: 1,
                show: 'fast',
                hide: 'slow',
                width: 600,
                height: 90,
                position: 'middle'
            }).width(600);
        }
    });

});

The structure of my HTML is as follows:

<a href="#/" class="next openModalBox lessOpacity">
    Go forward
<span class="modalBoxContent">
    <p style="font-size: .8em; text-align: center;">
            Lorem ipsum.<br />
            Lorem ipsum <a href="/index/index" class="accessible-link">lorem ipsum</a>.
        </p>
</span>
</a>

Additionally, the relevant CSS pertaining to this is:

span.modalBoxContent {
    display: none;
}

This implementation functions well when only text is present within span.modalBoxContent. However, when there is HTML code involved, the span does not remain completely hidden. In that scenario (refer to the HTML above), the link becomes visible.

Why does this occur and how can it be resolved?

Answer №1

Ensure your HTML is valid by using the W3C validator.

Remember, a span element cannot contain a p element. This can cause errors in rendering your content.

If you are using placeholder text, consider replacing it with more meaningful content to improve accessibility and semantics.

<a href="#id_of_related_content">link text</a>
<div id="id_of_related_content">
    Your initially hidden content here
</div>

And don't forget to set the correct href attribute for links.

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

What is the best way to retrieve the value of a textbox using jQuery and ajax?

I'm facing an issue where I am trying to retrieve a value from a textbox and display it in a table using jQuery. Strangely, when I try to access the "data" inside the success:function (data) of my AJAX call, it returns empty, but if I log it outside t ...

Is it possible to utilize a fixed callback method in JSONP to assist in caching the response?

I have a JSONP RESTful service that provides content based on request parameters. The majority of this content doesn't change often and can be cached easily. We are using Akamai edge servers and planned to cache many of these responses there. However, ...

When the dropdown menu is displayed, apply a class to the parent <li> element's

Encountering a frustrating problem where I'm trying to assign a class to an li a when its submenu is visible. However, the class is being added to all li a elements, including those in the submenu. <ul id="nav"> <li><a href="#" tar ...

Choose the heading element based on its class

I am trying to target a specific element by its class and store it in a variable, but I specifically need this element to be a heading element. To clarify: at any given time, there are always exactly 3 elements with this particular class on my page: an < ...

What's the best way to make sure the footer stays at the bottom of every page using CSS?

Here's the code I've been working on: #footer { font-size: 10px; position:absolute; bottom:0; background:#ffffff; } I'm facing an issue with this code - can anyone offer some assistance? UPDATE: To clarify the issue further: T ...

Attempting to conceal image on smartphones and tablets

Is there a way to hide the header image on for mobile devices only? I thought I had the right CSS code in place, as when I check the site on a virtual small screen, the image is hidden. @media (max-width: 768px) { .header-image { display:none ...

css Apply styles to form controls only if they are not empty

Utilizing an angularjs form, I have customized the following example to fit my code: .my-5 { margin:100px; } .form-group { position: relative; margin-bottom: 1.5rem; } .form-control-placeholder { position: a ...

Trouble with follow-up ajax request in jQuery in MVC 4 app

I have a partial view containing a form, and when I click a button I make an ajax call. The controller returns the partial view and it renders correctly. Everything works perfectly the first time, but subsequent clicks on the button do not trigger another ...

Progress Bar Rating System in Bootstrap 4

Trying to achieve a specific layout using Bootstrap 4: https://i.sstatic.net/Ym6Ov.jpg Disregarding "See All" and "4,327 Ratings" Progress so far has led to: https://i.sstatic.net/hPSRn.png The numerical ratings can be replaced with font icons. Provi ...

Using JavaScript to block form submission based on AJAX response

I am having trouble understanding why this code is not working as expected to prevent a submit. I have made sure all the HTML elements are properly linked and all alerts display correctly. It doesn't seem like I am losing scope on the event. If anyone ...

Deleting MySQL records with JQuery and PHP

Gradually, I've been transforming a PHP web application that I'm currently developing into Jquery AJAX form submissions. The specific issue I am tackling involves removing table rows. It seems like there is an issue with my JavaScript code becau ...

Passing an array with pre-defined variables using jQuery's Ajax functionality

Currently, I have a function set up to gather the contents of a form and send it to a PHP page for processing. However, I am facing an issue where no data is reaching the PHP page when sending it via POST or GET methods. function add_new_customer(){ $ ...

Various Plus/Minus Containers

One issue I am facing is that when using multiple counters on the same page, my - and + buttons to decrease or increase the number in a text box do not function properly. The script provided below works for one counter. How can I modify this code so that ...

How to create a vertical dashed line using React Native

https://i.sstatic.net/Mhbsq.png Looking for advice on implementing dotted vertical lines between icons in React Native. Any suggestions? ...

Manipulate links using Jquery to customize their behavior based on the URL

I'm facing a challenge with 3 links on a page, all having the same css class "suggested_product" and an integer id that needs to be included in the url. My goal is to modify what happens when these links are clicked. I have an ajax function set up to ...

creating interconnections between input fields by employing event listeners in JavaScript

I've been experimenting with binding multiple input fields to a span element using jQuery. Specifically, I have two input fields containing integer values and the sum of these values is displayed in a span element. I want the span element to update wh ...

The hidden absolute positioned div disappears once the sticky navbar becomes fixed on the page

Whenever my navbar reaches the top of the screen, the links in the dropdown menu disappear. I followed tutorials and examples from w3schools to build my webpage. Specifically: howto: js_navbar_sticky howto: css_dropdown_navbar This code snippet exempli ...

I'm curious why I can only see the HTML code and not the three.js code as well

I attempted to run a sample three.js game today, but only the HTML code appeared. I've also installed three.js with npm and tried running it with the VSC Live Server, but it's not working. You can find the source code here. What should be my nex ...

Highlight particular words within a string by assigning them specific colors

WordPress is my platform of choice. Initially, I crafted an HTML template and established a class for specific words within strings, which has proven to be successful. However, I am now contemplating whether it's feasible to apply this technique afte ...

Issue: The system does not recognize 'cleancss' as an internal or external command

After successfully installing clean-css via npm command line, I was eager to start using it to concatenate and minify some css files. However, my excitement quickly turned to frustration when I encountered this error: 'cleancss' is not recognize ...