0

I created a form to generate urlname and urllink. This form generate three element : 1- the span element (display urlname and in html urllink) 2- input hidden with urlname 3- input hidden with urllink.

fiddle

$(document).on("click", ".url_remove", function () {
    var refurllink = $(this).data("nburl");
    var allclasssameurl = $('.' + refurllink); // <- return [] or s.fn.init length 0
    //$(this).parent().closest('input[type=hidden]').find($('.' + refurllink)).remove();
    $('input[type=hidden]').find(allclasssameurl).remove(); //doesn't work
    $(this).parent().remove(); // works fine
}); // Delete link

Issue : the console display s.fn.init length 0 or [ ]

I don't know why I get this result. **I can't select the two inputs hidden closest of span. **

imagIne
  • 49
  • 1
  • 6

1 Answers1

0

Issue resolved : based on this answer I found the solution : jsfiddle updated For an unknown reason jquery must know how many element (div) have the same class using this expression $('.' + classname)... (var classname)

   var refurllink = $(this).data("nburl");
   var allclasssameurl = $("." + refurllink);
   for(var i = 0; i < allclasssameurl.length; i++){
      $(allclasssameurl[i]).remove();
   }

If I use a specific class name, which is the same as the var classname ('.urllinkref') it work perfectly without use incremental condition

If anyone can explain to me why jquery is making this distincton, thanks to him.

imagIne
  • 49
  • 1
  • 6