Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript remove element when dose not exist #jquery

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #270022
    hamid bourja
    Participant

    When i run this code
    for (var i = 0; i < 31; i++) {
    $( '#e-list-'+i ).clone().appendTo('#a-list-'+i);
    if ($('#e-div-'+i).length) {
    $( '#a-list-'+i).parents().remove();
    }

    }
    i get an error .

    #270026
    Mamun
    Participant

    I think length will be length()

    #270032
    hamid bourja
    Participant

    no my dear

    #270038
    Shikkediel
    Participant

    I think you might want to show the HTML markup as well, “an error” is quite undescriptive.

    #270176
    chris_2080
    Participant

    Error?
    ..if you remove the parents while you have them as selector in your for-loop
    – on the first pass, all parents (up to html-tag) will be removed.. then the selector’s are gone.
    – nothing to select for the next runs.

    show your html.
    what is the goal?

    edit: $(‘#e-div-‘+i).length is true if the element exist

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.