0

I have html like this

<table>
 <tr>
  <td>date</td>
  <td>name</td>
 </tr>
 <tr>
  <td>aug</td>
  <td>tr</td>
 </tr>
</table>

and this is the css external @media queries(max-width:768px)

td{
 display:block
}

How can I remove the display: block in external css using jQuery? I tried this but I think its only working on inline css

$("td").css({"display":""});

I cant remove the display: block in external css cause I need it in another pages

I tried to read this also but only removing the display was the best solution. Can anyone help me?

10
  • you want to hide? use .hide() Commented Jun 22, 2017 at 7:44
  • and I guess, this is not correct {"display":""}. You should set one of the "display" values not "" Commented Jun 22, 2017 at 7:47
  • @Pasha yes but i not to remove the display itself in just one page or override it. Commented Jun 22, 2017 at 7:52
  • that page has an id or class, which is it ? or what does that table on that page have in particular from other pages ? Commented Jun 22, 2017 at 7:56
  • @MihaiT i need to maintain the TD's as what is it when in mobile Commented Jun 22, 2017 at 7:59

3 Answers 3

1

If you say the page where you want to change the display:block style, doesn't have anything in particular that could differentiate it from other pages like an id or class. Or some wrapper outside the table etc. ,then you can't specify the style only for that page in particular.

You should know that you cannot just 'delete' styles. You can just overwrite them with other styles. All elements have a bunch of styles set by default. Like td have display:table-cell;visibility:visible;opacity:1 etc. . block elements have display:block etc. , see here css initial values

So what you can do is maybe set a specific class to that table you want to change, and then in css write

table:not(.myTable) td {
    display:block;
}

And so, the display:block style will NOT be applied to the desired table cells and the td will stay with default style, display:table-cell

You could also write ( if you don't want to change the style you already set )

table td {
     display:block;
}
table.myTable td {
      display:table-cell;
} 

Or there are many possibilities to change/overwrite css styles ( using css or javascript etc. ) , but you can't just 'remove' styles. As i said before, every html element has initial styles set for every property.

see snippet with CSS

td {
	display:block;
	color:red;
}
table.myTable td {
	display:table-cell;
	color:blue
}
<!-- Table with td display:block-->
<table>
<tr>
<td>aa</td>
<td>bb</td>
</tr>
</table>
<!-- Table with td display:table-cell-->
<table class="myTable">
<tr>
<td>aa</td>
<td>bb</td>
</tr>
</table>

overwrite property with JQ

$("td").css({
  "display": "table-cell",
	"color":"blue"
})
td {
  display: block;
  color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- Table with td display:block-->
<table>
  <tr>
    <td>aa</td>
    <td>bb</td>
  </tr>
</table>

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

7 Comments

I tried that also putting another property values on display still hopeless.
@PureRhymerOrganization how did you try to put the other property value ? you need to be as specific as possible, so you can overwrite the style already set. So write a more specific path like body #content table.myTable td { display:table-cell} . In worst case scenario use !important after the style, but i strongly suggest you avoid using it
By using jQuery I added another property value on it that listed on that site and display:table-cell doesnt work.
@PureRhymerOrganization added 2 examples. 1 with CSS 1 with JQ . one of them should work for you
I tried that also but it doesnt work trying to change the property values
|
1

You cant change external css property using javascript, but you can override those properties defined in external style sheet. javascript styles takes higher precedence than external style sheet

10 Comments

How can I override those properties? I used $("td").css({"display":""}); to override it but still no luck
That works properly, just check in your console is there any error
but that code only works on inline css it cant override the external css
It can override the external css if I put a correct property value of display for example .css({"display":"inline"}) it will override but in my case I need to remove the display
You must specify` key` and value pair
|
1

Please try the following:

$("td").css({"display":"table-cell"});

Did you try also this?

$("td").each(function () {
  this.style.display = '';
});

Otherwise you could add a class to override and reset the style to table-cell.

1 Comment

I tried all display property values but still not fixing my problem but by removing the display itself it will fix my problem

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.