Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

167
Views
How to give background-color to specific <td>? For that i have to enter position number in 3rd textbox (using java script)

I created three textboxes.

  • 1st text box takes a number as a row
  • 2nd text box takes a number as a column
  • 3rd text box takes a number(position) for highlighting that number in the table
  • how to do 3rd point in javascript
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="7.js"></script>
    <title>Document</title>
</head>
<body>
    <input type="text" name="" id="text1">
    <input type="text" name="" id="text2">

<label for="color">Which cell to color</label>
<input type="text" name="" id="color">
    <input type="button" value="Generate" onclick="h()">
    <br>

<!--javascript code-->
<script>
function h(){
var a=document.getElementById("text1").value;
var b=document.getElementById("text2").value;
var col=document.getElementById("color").value;
var g=parseInt(col);
document.write("<table border='1'>");
var c=1;
for(i=0;i<a;i++)
{
    document.write("<tr>");
    for(j=0;j<b;j++)
    {
document.write("<td>",c++,"</td>");

}
    document.write("</tr>");
   
}
document.write("</table>");

}
</script>

</body>
</html>


about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="7.js"></script>
  <title>Document</title>
</head>

<body>
  <input type="text" name="" id="text1">
  <input type="text" name="" id="text2">

  <label for="color">Which cell to color</label>
  <input type="text" name="" id="color">
  <input type="button" value="Generate" onclick="h()">
  <br>

  <!--javascript code-->
  <script>
    function h() {
      var a = document.getElementById("text1").value;
      var b = document.getElementById("text2").value;
      var col = document.getElementById("color").value;
      var g = parseInt(col);
      document.write("<table border='1'>");
      var c = 1;
      for (i = 0; i < a; i++) {
        document.write("<tr>");

        for (j = 0; j < b; j++) {
          if (parseInt(col) == c) {
            console.log(col)
            document.write("<td style='background-color: yellow;'>", c++, "</td>");
          } else {

            document.write("<td>", c++, "</td>");
          }


        }
        document.write("</tr>");

      }
      document.write("</table>");

    }
  </script>

</body>

</html>

about 4 years ago · Juan Pablo Isaza Report

0

set background of all td nth possition

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="7.js"></script>
    <title>Document</title>
</head>
<body>
    <input type="text" name="" id="text1">
    <input type="text" name="" id="text2">

<label for="color">Which cell to color</label>
<input type="text" name="" id="color">
    <input type="button" value="Generate" onclick="h()">
    <br>

<!--javascript code-->
<script>
function h(){
var a=document.getElementById("text1").value;
var b=document.getElementById("text2").value;
var col=document.getElementById("color").value;
var g=parseInt(col);
document.write("<table border='1'>");
var c=1;
for(i=0;i<a;i++){
    document.write("<tr>");
    for(j=0;j<b;j++){
        var background = '';
        if(g == j){
            background = 'style="background-color:red"';
        }
        document.write("<td "+background+">",c++,"</td>");
    }
    document.write("</tr>");
}
document.write("</table>");

}
</script>

</body>
</html>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!