How to add cellspacing="0"
if it's not available for any <table>
using jquery?
and if it's available and it has any other value than ="0"
then want to convert it to ="0"
How to add cellspacing="0"
if it's not available for any <table>
using jquery?
and if it's available and it has any other value than ="0"
then want to convert it to ="0"
$('table').attr("cellspacing", 0);
Will change every table's cellspacing attribute to 0, whether it was previously defined or not.
Starting HTML:
<table> ... </table>
<table cellspacing="5" cellpadding="5"> ... </table>
Resulting HTML:
<table cellspacing="0"> ... </table>
<table cellspacing="0" cellpadding="5"> ... </table>
<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
}