"Upon entering text into input fields, the css attributes are reset and lost

My HTML table contains cells

<table id="grid">
      <tr>
        <td><input type="text" id="1" /></td>
        <td><input type="text" id="2" /></td>
        <td><input type="text" id="3" /></td>
        <td><input type="text" id="4" /></td>
        <td><input type="text" id="5" /></td>
        <td><input type="text" id="6" /></td>
        <td><input type="text" id="7" /></td>
        <td><input type="text" id="8" /></td>
        <td><input type="text" id="9" /></td>
      </tr>
      <tr>
        ...
         <td><input type="text" id="81" /></td>
        
      </tr>

  </table>

The CSS styles the cells for editing and hovering

* { box-sizing: border-box; }
table { margin: 10px; }
....
input:hover {
    background: #eee;
}

I used JavaScript to populate the cells with values

document.querySelectorAll('td').forEach((cell) => {
     cell.textContent = "1";
})

However, using 'textContent' causes issues with the CSS. It disables editing and hover effects, and changes the font. Any advice on this?

Your assistance is appreciated. Thank you

Answer №1

Ensure you are assigning the value to the input element, not the cell itself, for example:

document.querySelectorAll('td').forEach((cell) => {
    cell.querySelector('input').value = '1'
})

Additionally, keep in mind that CSS does not control cell editing capabilities, as cells with input elements are inherently editable.

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

Can we iterate through an array containing arrays of objects in a loop?

Here is an example of how I want my solution to appear: https://i.sstatic.net/B9AW1.png Currently, I have created an array where I group items by their first letter, like this: const grouped = _.groupBy(topicPages, key => key.relatedTopic.title[0]); ...

Using AngularJS to show/hide elements within a colgroup tag

Looking to create a dynamic table allowing users to hide certain columns. Wondering if it's possible to use ng-show with colgroup or col tags instead of adding ngshow to each cell individually. Struggling to make it work... <colgroup ng-repeat="mt ...

The success body of Jquery Ajax is not receiving any response

Despite trying various methods, I have been unsuccessful in retrieving the desired result from my jQuery ajax success function. I have included the jQuery library, but to no avail. Any guidance on where I may be going wrong in my code would be greatly appr ...

Is it possible to use Harvest's Chosen alongside the Python Pyramid Framework?

Is it possible to set up npm to install chosen on a Linux server running Fedora in Amazon's AWS service? If not, are there any alternatives available? I'm currently using a python framework and wondering if it's safe to install node.js on t ...

Capturing user input with JavaScript and storing it in a database: A step-by-step guide

In this script, a function is defined to add dynamic rows to a table when clicking on the add button. The function inserts new rows with input fields for id, item, cost, wholesale price, retail price, and a save button. Now the task is to get the values e ...

"Troubleshooting: The v-model in my Vue project is not functioning properly when used

I am encountering an issue where the v-model directive is not functioning properly inside a v-for loop. Within my template <li v-for="(data, key) in product.variants" :key="data.id"> <input type="radio" :id=" ...

Is there a way to modify the text within a "span" element that directly follows an "i" element using jQuery?

I am attempting to modify the text displayed on a button within a plugin by using jQuery. Here is the outer HTML: <button value="[[3,1,1488182400]]" data-group="2017-02-27" class="ab-hour"> <span class="ladda-label"> <i class="ab-hour ...

Is there a way to extract all the class names from a JavaScript file?

I am currently working on developing a code to showcase all the public properties of a class that are available in a JavaScript file. As of now, the user has to manually input the name of the class in a text box. However, my goal is to enhance user experie ...

What is the best way to retrieve a value from a promise within a nested promise?

Can the value of result2 be accessed outside the promise? If so, how can it be done? For Example someFile1.someFunction1(req).then((result1)=>{ . . . someFile2.someFunction2(req).then((result2)={ return(result2); }); return(resul ...

Despite successfully connecting to my webservice, the ajax function encounters an error

<script type='text/javascript'> $(document).ready(function () { $("#submit").click(function (e) { e.preventDefault(); var userName = $("#username").val(); var pwd = $("#password").val(); authenticate(use ...

The ashx file is triggered with every server control postback in jqgrid

I have an asp .net webforms page with a jqgrid, as well as several other server controls. The jqgrid is populated using an ashx file which retrieves data from the database and binds it successfully. Challenge Whenever a postback occurs (such as from a dro ...

Prevent interruptions on mouse hover -Full Slider

In my most recent web development project, I incorporated the Full Slider component from Iron Summit Media (https://github.com/IronSummitMedia/startbootstrap-full-slider). It functions as a background image slider. However, I encountered an issue where ...

Storing account information in a .env file can be a more secure option compared to storing it in a client

Working on a basic nodejs application using express for file processing operations. Planning to package the final app with pkg. I need to implement a login system and one time account creation. The app will launch a browser tab running a vuejs UI app. Cons ...

"Guide to triggering the display of a particular div based on its class when clicked

I have multiple div elements with the class name dis HTML: <div class="dis">Content</div> <div class="dis">Content</div> <div class="dis">Content</div> and so on ... Additionally, there are various images: <img sr ...

Can you explain the meaning of the tag "&" ">" "*" in the context of useStyles functions?

After experimenting with React and Material-UI, I came across an interesting pattern in the code. When using the useStyle function, developers often create a class called 'root' and utilize the tag & > *. I tried to research the meaning be ...

Sorting objects with Javascript

users[usernames] = { userName : username, userId : id, userStatuINT : statu, userMobilemi : mobile, }; Console log : console log(JSON stringify(data)); Output : { "Guest-77": {"userName":"Jack","userId": ...

"Optimizing Text Display on MAC Computers through Word Wrap

While constructing a form using Bootstrap3, I encountered an issue where only one word in a checkbox label wraps to the next line specifically on MAC safari/chrome browsers. Interestingly, this problem doesn't occur with other browsers such as IE or o ...

Integrate jQuery into your Spring MVC application

Struggling to integrate jQuery into my Spring MVC application as a beginner in Spring MVC. I've created a 'js' folder under the webapp directory, but unsure how to include the file in my view. I attempted: <script type="text/javascript" ...

Implement custom material-ui styles exclusively for mobile displays

When working with Material-UI in react, I am wondering if there is a way to apply theme provider overrides only in mobile view. Specifically, I am using the <Card> component and would like to remove the boxShadow of the card when it's displayed ...

Creating DOM elements upon successful completion of an AJAX request with jQuery has never been easier. Here's a

I'm currently working on a project where I am dynamically creating a list of checkboxes using jQuery's $.ajax method. function load() { $.ajax({ type: "POST", url: "*************", data: "************ ...