I’m having a problem trying to detect if a table exists using jQuery. The table has no class or ID.
What I’m trying to achieve is to not have the following code fire unless a table exists:
function tableAltRows()
{
$("#content table tr:even").each(function(){
$(this).addClass("alt");
});
}
$(tableAltRows);
So I changed the last line to:
if ($('table').length > 0) {
$(tableAltRows);
}
But the line checking the table length never returns anything other than 0. As a test, if I change it to == 0 it calls the tableAltRows function. I’m not that familiar with jQuery, so I assume I’m missing something obvious?
Using the OBJECT_ID and the IF ELSE statement to check whether a table exists or not. Alternative 2 : Using the INFORMATION_SCHEMA. TABLES and SQL EXISTS Operator to check whether a table exists or not.
To test whether a row exists in a MySQL table or not, use exists condition. The exists condition can be used with subquery. It returns true when row exists in the table, otherwise false is returned. True is represented in the form of 1 and false is represented as 0.
declare cnt number; begin select count(*) into cnt from user_tables where table_name = 'EMP1'; if cnt>0 then execute immediate 'truncate table emp1'; DBMS_OUTPUT. PUT_LINE('Truncated the table'); else execute immediate 'create table emp1 as select * from emp'; DBMS_OUTPUT.
if table exist or not. cal IF_table_exist('table_name') or select iftableexist('table_name');
I suspect that you're not calling your function when the DOM is ready. Try:
$(document).ready(function() {
if($('table').length) {
alert('hello');
}
});
If you are calling the element before it exists, it will not work.
You can:
See this example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With