Ways to display a div using its unique identifier and adjust visibility from hidden to visible?

Can anyone help me with a JavaScript code that will locate a hidden div by its Id and change the style from display:none; to display:block; ? HTML:

<div id="author-info" style="display:none;">by Jane</div>

Every post on my website begins with this HTML code. How can I display or show the element based on its Id? Thank you!

Answer №1

<script>document.getElementById("post-author").style.display="block";</script>

For the desired effect, simply insert this code into the head section of your website.

Answer №2

Although this question has been asked numerous times, here is the solution:

document.getElementById('post-author').style.display = 'none';

Alternatively,

document.getElementById('post-author').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

How can one transfer information from a client to a server and complete a form using JavaScript?

Can the information be transferred from a client to the server using just JS, then fill out a form on the server, and finally redirect the client to view a pre-filled form? I am considering utilizing AJAX to send a JSON object, but unsure if it will be s ...

Is there a way to transform data from a CSV format to a JSON format?

I've written the code to fetch data from a device in CSV format. Here are some sample data values: 1,1.635946,1.636609,1.640240,1.636091 2,1.642825,1.640267,1.639013,1.636568 3,1.636835,1.636022,1.637664,1.637144 4,1.641332,1.641166,1.637950,1.640 ...

Determine the number of entries in a JSON object

I am encountering an issue while trying to calculate the number of records in a JSON object, as I am getting an incorrect count. Snippet var jsonObject = {"d":"[{\"Country\":\"\",\"CountryCo ...

Using TypeScript to categorize items based on common characteristics and assigning them a unique group ID

I am looking to create a function that can achieve the following: Accepts an array of products as input Returns a new array of products with a unique groupId attribute for each Products will share the same groupId if they have common attributes specified ...

Generating a JSON Object by combining elements from multiple arrays

I need assistance in creating a single Json object from two arrays using JavaScript or jQuery. The data is stored in the database in the format shown below: clob_field_1: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 etc etc ... clob_field_2: 8106.23, 7856.49, 8009.15, ...

Every time I click on my page, the Bootstrap datepicker automatically sets the current date

I've encountered an issue with my bootstrap date-picker and knockout integration. The problem arises when I click anywhere on my html page, as it triggers the datepicker set value action, setting the current date instead. Is there a way to prevent th ...

Update the input tag's value dynamically using another input element without the need for jQuery

I am working with 2 input tags Title: <b-input style="width: 50%" v-model="value.title" class="input-element" placeholder="Title" v-on:click="greet" /> Id: <b-input id="id" style="width: 50%" ...

Turning align= into float in Javascript:

When creating an HTML newsletter, I am required to use the deprecated align attribute to position images. While this works well in emails, it does not have any effect in IE. Is there a way to target elements containing the align attribute and convert it ...

Guide to packaging TypeScript type declarations with an npm JavaScript library

I'm facing an issue with providing TypeScript type definitions for a JavaScript library. The library itself is written in TypeScript and transpiled by Babel, although this detail shouldn't affect the outcome. The problem lies in the fact that ne ...

Some of the Tailwind CSS colors may not be fully supported by Next.js for rendering

Don't forget to showcase all the amazing Tailwind CSS Colors, Sometimes they go missing unexpectedly, and only a few decide to make an appearance. I try to add them manually one by one, but sometimes they just don't show up on the map. Edit: ...

Disordered block elements

I am having trouble centering a div in my footer. When I try to center it, the div ends up floating on top of the footer instead. Here is the link to the codepen. footer { text-align: center; background-color: grey; position: fixed; bottom: 0; width: 100 ...

Formatting numbers in JavaScript objects

I am looking to iterate through an array of objects and convert the string values into numbers. Here is a sample scenario: I have data in a format similar to the variable provided below. When passing this array to a kendo chart, it seems to have trouble r ...

Error: Attempting to access the text content of a null object

I recently followed a tutorial on text reveal animation and attempted to implement it in Next.Js. Unfortunately, I encountered an error message stating "TypeError: Cannot read properties of null (reading 'textContent')". Here is the video tutori ...

Enhance the appearance of JSON data in Angular 2 with the Prettify

I'm encountering an issue where my JSON is not being printed in a pretty formatted way and is returning with unnecessary \ characters. The solution I found on Plnkr works well there, but strangely doesn't work in my actual application. The ...

Error: Null value detected while trying to access the property 'appendChild'

Can anyone help me with this error? Uncaught TypeError: Cannot read property 'appendChild' of null myRequest.onreadystatechange @ script.js:20 Here's the code snippet where I'm facing the issue // index.html <html> <he ...

Ways to conceal a div element on the initial page while displaying it on a separate page

In the initial div of my first page, I have some typical content: <div id="news"> <div class="loginform"> <div id="form_news"> <form id="loginform" method="post" action="envianews.asp"> ...

Twice Triggered: Firebase Cloud Function HTTPS Call

I have thoroughly reviewed the Firebase Cloud Functions reference, guides, and sample code in an attempt to solve the issue of my function being triggered twice, but so far, I have not found a solution. I also experimented with Firebase-Queue as a workarou ...

adjusting the size and positioning of an image within a parent div using React

Hey everyone, I'm a newcomer to the world of React. Currently, I'm working on a website and everything seems to be falling into place nicely. However, I've encountered a little hiccup. My goal is to write code within my SCSS folder that will ...

Function not returning the value as anticipated

After receiving a CSV file from a URL, I am converting each row into an array of objects. const translation = { '緯度': 'latitude', '経度': 'longitude', '測定局コード': 'Measuring ...

Showing information from the data text option

I'm having trouble displaying text below the cube. The code works fine in a standalone fiddle, but it doesn't work when I incorporate it into my project. Can someone help me figure out how to show the value of data-text="Cube1"? Code t ...