1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to make function give row that have different value with color red to full row ?

Discussion in 'jQuery' started by ahmedsalah, Feb 5, 2020.

?

How to make function give row that have different value with color red to full row ?

  1. jquery function

    0 vote(s)
    0.0%
  2. java script function

    0 vote(s)
    0.0%
  1. #1
    problem

    How to make row that have different value with color red font to full row ?

    I have html dynamic table not static meaning i dont know how many rows or column inside table because it changed based on data show from back end .

    I need to give color red to row have distinct value according to my case then second row and third row will be have font red and first row will not be change color .

    First row have similar value as 12 on all td so that color will not change .

    But second row have distinct value or different value 15 so that will be red font to full row completely .

    third row have distinct value or different value as 17,15,13,12 so that third row completely will have red font .

    meaning if I have one value or more different value from each other on same row then full row or all td on tr will be change font to red .


    Actually i need function jquery or javascript give row that have different value with color red to full row ?

    can you please help me on that ?

    sample below for explain


    
    
    <!DOCTYPE html>
    <html>
    <body>
    <table border="1">
    <col width="500">
    <col width="500">
    <col width="500">
    <col width="500">
    <tr bgcolor="#6699FF" width="100%">
        <th>Part1</th>
        <th>Part2</th>
        <th>Part3</th>
        <th>Part4</th>
    <tr>
        <td>12</td>
        <td>12</td>
        <td>12</td>
        <td>12</td>
    </tr>
    <tr>
        <td>12</td>
        <td>15</td>
        <td>12</td>
        <td>12</td>
    </tr>
    <tr>
        <td>17</td>
        <td>15</td>
        <td>13</td>
        <td>12</td>
    </tr>
    </table>
    
    <button id="button">Click Me</button>
    </body>
    </html>
    
    
    
    HTML:
     
    Last edited by a moderator: Feb 5, 2020
    ahmedsalah, Feb 5, 2020 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,641
    Likes Received:
    4,486
    Best Answers:
    123
    Trophy Points:
    665
    #2
    first of all if you're using jquery and have tables you need to mess with you should be using datatables.

    having decided to use that it's just a matter of giving values to the json feed as you output the database values.
     
    sarahk, Feb 5, 2020 IP
  3. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #3
    The COL tag on its own without a COLGROUP is gibberish, but since you're setting them all the same value (a ridiculously and abusrdly high one at that) AND using them for presentation NONE of that belongs in your markup. That's style, put it in the stylesheet.

    Likewise attributes like BGCOLOR haven't been valid since 1997, STOP THAT. Again, that's the stylesheet's job.

    TR don't even HAVE a WIDTH attribute. 100% width also being inconsistent/incompatible with your declared COL.

    ... and where's your THEAD and TBODY, much less your SCOPE?

    As to generating it dynamically and colouring a row, that's ALSO your stylesheet's job just give it a class like "whyIsThisGettingColor" or some other descriptive name of WHY it's different (and not what it looks like) when you dynamically generate it. Hopefully you're doing that on the DOM and not the garbage outdated innerHTML mental midgetry

    Remember, saying what things look like is NONE of HTML's business, and if you choose your HTML tags based on their default appearance you're choosing all the wrong tags for all the wrong reasons. Which is why when I see HTML like that I assume people haven't learned enough HTML to be playing with CSS or JavaScript yet.

    To say much more I'd have to see the scripting that's generating said table.
     
    deathshadow, Feb 21, 2020 IP