The JavaScript code embedded within this HTML is taking precedence over the CSS property

The internal JavaScript is overriding the CSS property in this HTML code. Initially, I set the value of ID bad to none using CSS, but it is not working as expected in the code example below. The JavaScript function associated with the ID bad does not execute properly and displays data before clicking on the image.

How can I resolve this issue?

function myFunction(){
    document.getElementById("bad").style.display = "block";
}

Other styling rules are also defined for IDs like #good, #vahid, #isnani, #one, #boom, etc., along with classes for images and text within the HTML structure. There seems to be a conflict or error causing the display issue. Any suggestions on how to fix this problem would be appreciated.

Answer №1

                                                                                      
    function myFunction(){                    
        document.getElementById("bad").style.display="block";
    }
    
    #good{
        width: 100%;
        height: 100%;
    }
    #bad{
        position:absolute;
        width: 15%;
        height: 100%;
        background-color: #023b3b;
        top:0%;
        display: none; 
    }
    #vahid{
        float: left;
        width: 7%;
        height: 100%;
        background-color: #023b3b;
    }
    #isnani{
        float: left;
        width: 93%;
        height: 100%;
        background-color: bisque;
    }
    .
    .
    . (Continue with the rest of the CSS code)
  
 
    <html>
        <head>
            <link rel="stylesheet" type="text/css" href="rise.css">
                      <link rel="stylesheet"       href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css">
          
        </head>
        <body>
            <div id="good">
                <div id="vahid">
                    <div id="one">

                                                                                        
                        <img src="image1.jpg" id="boom"><br><br><br><br><br>
                        <!--button-->
                        <i class="icon fa fa-anchor"  onclick="myFunction()"  id="button"></i>
                       <!-- <img src="button.jpg" onclick="myFunction()"  id="button">--><br><br><br><br>
                        <!--icons-->
                            <span class="local">
                                <img src="img.jpg">
                                <img src="img1.jpg">
                                <img src="img2.jpg">
                                <img src="img3.jpg">
                            </span><br><br><br><br>
                            <span class="local">
                                <img src="img4.jpg">
                                <img src="img5.jpg">
                                <img src="img6.jpg">
                                <img src="img7.jpg">
                            </span>
                    </div>
                </div>
                <div id="isnani">
                     <div id="third">
                        <p >
                            <span class="fourth">Dashboard</span>      
                            <span class="fifth">  + New</span>
                        </p>
                        .
                        .(Continue with the HTML code)
                         

Answer №2

When the page is loaded, an issue arises:

VM429:45 Uncaught SyntaxError: Missing semicolon

Also, when attempting to click a button in the console:

VM589:72 Uncaught ReferenceError: functionName is not defined

The root of the problem lies in the missing parentheses within your function. Revise it as follows:

  function functionName() {
    document.getElementById("incorrect").style.display = "block";
  }

See demo here.

Answer №3

There appears to be a syntax error. Take a closer look at how you have defined the function.

 function myFunction{                        
                                    document.getElementById("bad").style.display="block";
                              }

It should actually be:

 function myFunction**()**{                        
                                    document.getElementById("bad").style.display="block";
                              }

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 could be causing the repeated calls to a computed function in vuejs?

In my Vuejs application, I start by fetching initial data and setting it in the store: const app = new Vue({ router, store, mounted: function() { var that = this; $.get("/initial_data/", {}, function(data) { that.$s ...

How to retrieve the first option selected in Material-UI React?

Hey there! I am currently working with React Material UI select. I have a question - how can I set the first option of items as selected without triggering the onChange method? When I change an option, it triggers the onChange method and adds an attribut ...

Steer clear of manually inputting URLs in your React components

As I embark on my journey with Gatsby, I am noticing a recurring pattern in my code. A prime example is when creating links, where I often find myself doing something like this: import {kebabCase} from "lodash"; // ... <Link to={`tags/${kebabCase( ...

Locating elements with Selenium Webdriver using xpath

<a style="color:White;" href="javascript:__doPostBack('dnn$ctr674$Case$gvCaseSearchDetails','Page$777')">777</a> Can anyone help with writing an xpath for the HTML code above? The goal is to locate elements using the identi ...

What causes block elements to act like inline elements?

:target { border: 2px solid #D4D4D4; background-color: #e5eecc; } .navigation li { list-style-type: none; float: left; padding: 1em; } <ul class="navigation"> <li> <a href="#help"> Help </a> </li> <li> & ...

JavaScript popup menu with a redirect URL

I utilized Tinybox from this source for launching a popup webpage. I am hoping that when I click the links on the webpage, the popup will close itself and redirect to the link's URL. Here are my JavaScript and HTML codes: <script type="text/java ...

Tips on utilizing chaining technique for ajax requests within jQuery

I have multiple Ajax requests that need to be executed in sequence. $.ajax({ url: 'https://dummyjson.com/products/1', success: (res) => { console.log(1, res); $.ajax({ url: 'https://dummyjson.com/carts/1', ...

What could be causing certain icons in my jQuery to appear distorted?

My app utilizes jQuery mobile, and everything was functioning properly until I recently noticed that two components do not appear as they should. The first issue is with a selection field that used to display a small arrow but now shows an empty gray circ ...

Troubleshooting issues with an external JavaScript file

Recently, I moved my JavaScript code from being loaded at the bottom of my website to an external file. However, after this change, the code is now breaking and pointing to an error in the jQuery file rather than within the JavaScript itself. What could be ...

What is the best way to ensure a "child" div does not overflow on its own and instead utilizes the padding of its parent div for rendering?

Initially, here are my code snippets: In the HTML file: <div class="div parent"> Title <div class="div child"> <div class="overflowed"> </div> </div> </div> CSS Styling: .div { border: 1px solid #0000 ...

Is the main content positioned below the sidebar on smaller screens?

In order to achieve a 250px col-2 sidebar with a col-10 main body that collapses into a top navbar and main content beneath it, my goal is set. However, I am facing an issue where the main content body goes underneath the sidebar when the screen size cha ...

The Kendo UI Grid will consistently begin at Page 0

I have a Kendo UI Grid and it always starts at 0. When I change the sort on a column, it goes to 1 and displays the other page numbers. What could be the issue? Below is the code snippet: $('#userGrid').kendoGrid({ dataSource: ...

Achieving perfect centering in PrestaShop using CSS for both horizontal

Hello there, I require assistance with aligning some images in the center of my Prestashop webpage. I am specifically struggling with aligning 3 circular images at the bottom of the page (not social icons). I cannot figure out how to properly center these ...

Header on top of table that stays in place with scrolling

I'm facing an issue with a table that contains user-generated data. We are utilizing a plugin known as Clusterize, which allows us to smoothly scroll through large amounts of rows. However, the specific markup required for this plugin seems to be caus ...

Dynamic form population with dropdown selection using Ajax - Coldfusion continuation

Following some valuable feedback from my previous inquiry, I have made progress: Refer to the original post - Coldfusion Populate form with dropdown selection using ajax Currently, I have successfully sent a request to my CFC with a remote function, but I ...

When the jQuery button is clicked, the execute function will run multiple times

I am attempting to create a button using jQuery that calls a JavaScript function, but I am facing an issue : Upon loading the page, the first click on mybutton does not elicit any response The second click results in the function being executed twice On ...

The issue of receiving a 400 (Bad Request) error when making an ajax post call with an array to a Spring

My database schema includes a OneToMany mapping defined as follows: @Entity public class Foo implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private long ...

Difficulty navigating to different sections of a webpage using HTML

I'm facing a strange issue. The title pretty much sums it up. Here's a snippet of the code: <a href="#test1">Go to test 1</a> <a href="#test2">Go to test 2</a> <a href="#test3">Go to tes ...

Issue with Vue not displaying HTML content retrieved from an API

I am currently utilizing Vue in a Shopify environment and focusing on enhancing a collection page. The issue I encountered is that when clicking on a filter, it acts as an href which updates the URL and triggers a page reload. My objective is to display a ...

Locate records in MongoDB by leveraging the power of Mongoose

Managing two distinct databases, one for products and another for categories. The product schema is defined as follows: const productSchema = new mongoose.Schema({ name: { type: String, required: true }, description: { type: String, required: true }, ...