简体   繁体   中英

How to show div which is inside table tr td tag?

I have put my div in table tr td tag and i want to find that div and show that div with jquery but it is not working.

I have 1 validate javascript function in which i want to find my div with id errordiv and make it visible but i am unable to make it visible as it is by default set to display:none ;

Here is my code:

function Validate() {
  $("table tr td #errordiv").show();
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<table>
  <tr>
    <td></td>
    <tr>
      <tr>
        <td></td>
        <tr>
          <tr>
            <td><label>Validate</label></td>
            <td>
              <asp:TextBox ID="txt1" runat="server" onchange="Validate();"></asp:TextBox>
            </td>
            <td><div id="errordiv" style="display:none;">
                <label for="errormessage">Incorrect</label>
                </div>
            </td>
          </tr>
</table>

try this

function Validate() {
  $("#errordiv").css("display","block");
}

This is what I would do.

jQuery:

function Validate() {
  $("#errordiv").css("display","block");
}

HTML:

<table>
<tr>
<td>
</td>
<tr>

  <tr>
    <td>
    </td>
    <tr>

      <tr>
        <td>
          <label>Validate</label>
        </td>
        <td>
          <input onkeypress="Validate();" />
        </td>

        <td>
          <div id="errordiv" style="display:none;">
            <label for="errormessage">Incorrect</label>
          </div>
        </td>
      </tr>

This will work in this case,

$('table').find("div").show()

If you have single div inside table.

<!DOCTYPE html>
<html>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>


<script>
    $(document).ready(function () {



    });

    function Validate() {
        $("table tr td #errordiv").show();
    }
</script>



<body>

  <table>
  <tr>
    <td>
    </td>
    <tr>
      <tr>
        <td>
        </td>
        <tr>
          <tr>
            <td>
              <label>Validate</label>
            </td>
            <td>
              <input ID="txt1" onchange="Validate();" />
            </td>
            <td>
              <div id="errordiv" style="display:none;">
                <label for="errormessage">Incorrect</label>
              </div>
            </td>
          </tr>
</table>
</body>
</html>

javascript

<script type="text/JavaScript">
    $(document).ready(function(){
        $("#errordiv").hide();
       $("input").change(function Validate() {

            $("#errordiv").show();
        });
    });
</script>

html

<table border="1">
    <tr>
         <td>
            <label >Validate</label>
         </td>
         <td>
           <input type="text" onchange="Validate()">
         </td>
         <td>
           <div id="errordiv">
              <label for="errormessage">Incorrect</label>
           </div>
         </td>
    </tr>
</table>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM