` using jquery? How to add cellspacing="0"if it is not available to anyone <...">

How to add cellpacing = "0" if it is not available for any `<table>` using jquery?

How to add cellspacing="0"if it is not available to anyone <table>using jquery?

and if it is available and has any other value than ="0", then you need to convert it to the value "0"

+3
source share
2 answers
$('table').attr("cellspacing", 0);

Changes the tablecacing table attribute to 0, regardless of whether it was previously defined or not.

HTML launch:

<table> ... </table>
<table cellspacing="5" cellpadding="5"> ... </table>

HTML Result:

<table cellspacing="0"> ... </table>
<table cellspacing="0" cellpadding="5"> ... </table>
+9
source
 <table id="table_id" cellspacing="0px">
 .................

Try:

if ($('#table_id').attr('cellspacing')) // does attribute exit
{
  if ('0px' != $('#table_id').attr('cellspacing'))
  {
    $('#table_id').attr('cellspacing', '0px') // make its value 0
  }
}
else // attribute does not exist
{
  $('#table_id').attr('cellspacing', '10px') // add
}
0
source

Source: https://habr.com/ru/post/1752023/


All Articles