April 17, 2012

Slide upping in jquery with ids

Question by Mert Metin

var Ids = $('.head:has(:checkbox:checked)')
               .map(function() { return this.id })
               .get(); alert(Ids);

i have ids with above code.However,
i cannot slide up with these Ids with

Why this does not work ?

function(response){
        alert("Başarıyla silindi");
         $('#'+Ids).each('slow', function() {
    }).slideUp();

Answer by Starx

First of all Ids is an array, so you cannot directly use $("#"+Ids).

Next, even if Ids was not an array and referrred to a string variable $("#"+Ids) would return an HTML element, which does not have .each() function.

The correct way to do this is

$.each(Ids, function(v) {
  $("#"+v).slideUp("slow"):
});

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!