-1

I have a function that suppose to add a row to a table depending on screen resolution. The problem is that I do not know how to adapt this part $("tblPotrawy > tbody td").... in order to modify appropriate table. I tried $("tblPotrawy..., $("#tblPotrawy... and none of these work.

Can you please advice how can this be used?

function potrawyEdycjaInfo(nazwaPotrawy){
        
        if ($(document).width() < 1400) {
            var tblPotrawy = $("#tblPotrawy1280");
        }
        else {
            var tblPotrawy = $("#tblPotrawy1920"); 
        }

        $("tblPotrawy > tbody td").each(function(i, el) {
            if ($(el).text() === nazwaPotrawy) {
                $(el).parent().after('<tr id="edycjaInfo"><td>test</td></tr>');
            }
        });
    
    }
3
  • 1
    tblPotrawy is a jQuery object that has one element - the table. So... -> tablePotrawy.find(...).each(...) Commented Mar 18, 2022 at 8:28
  • Indeed it works in this way. Thank you :) Commented Mar 18, 2022 at 8:33
  • Alternatively, var tblPotrawy = "tblPotrawy1280" then $("#" + tblPotrawy + " > tbody... (or string literal of course) Commented Mar 18, 2022 at 9:20

1 Answer 1

0

if you want to change the style ( css ) depend on resolution , best way is to use media query :

/* Set the background color of body to tan */
body {
  background-color: tan;
}

/* On screens that are 992px or less, set the background color to blue */
@media screen and (max-width: 992px) {
  body {
    background-color: blue;
  }
}

/* On screens that are 600px or less, set the background color to olive */
@media screen and (max-width: 600px) {
  body {
    background-color: olive;
  }
}

link : https://www.w3schools.com/css/css3_mediaqueries_ex.asp

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.