How do you make a JavaScript function have a false option, which makes sure the function doesn’t execute?
Here’s the code:
function deleteExtraRows(tableID){
tableID = '#'+tableID;
$(tableID+' tr').each(function(){
if($(tableID+' tr').length>1){
$(this).remove();
}
});
}
I want to also be able to give it a (false) option, so I can run deleteExtraRows(false), which will not make the function run. I know this seems kind-of backwards, but it would fit in the project I’m working on if I can do this.
Please help!
This should do the trick:
It is important to use
===as opposed to==since===checks the type as well. If tableID were 0 or an empty string, it would evaluate to true and return as well.