How to check if an element exists using jquery

    There are many ways to check if an element exists or not using jquery:
    if ($('#elementid').length > 0) {
       //your jquery code here
    }

    or simply
    if ($('#elementid').length) {
       //your jquery code here
    }


    Also

    if ($('#elementid').size()) {
       //your jquery code here
    }
    5
    Average: 5 (1 vote)

    User login