0

Hey everyone,
I just got a solution from here, but I think I spoke to soon, as I ran into another problem right away. I have been playing around with it for a couple days now, and just hoping that someone could explain or see why it isn't working.

I want to make a call to a dynamic element like so... $("#"+item_b).remove(); But it doesn't work, I put the entire code below for reference.

Here is a snippet of the code:

var img = $('<img>').attr({
      src: fileObj.filePath,
      alt: fileObj.name
      }).css({
      height: "100px",
      margin: "0 5px"
      });
      var txt = $('<span>').html(fileObj.name + ' uploaded.');
      var link = $('<a>')
      .attr({ href: '' })
      .text('Upload Different Image')
      .click(function(f){
      return function(){
      del_image(f.filePath,f.name);
      return false;};
	  }(fileObj));//call immediately forming closure to capture current fileObj attributes
	  
	  $('preview_logo').append('<div id=\"'+fileObj.name+'\"></div>'); //The div does get created
$('#'+fileObj.name).append(img).append(txt).append(link);/>'); //but this doesn't get put in the div

And the function:

function del_image(item_a, item_b){
	$("#logo_upUploader").show(); 
	$("#uploadifyUp").show();
	//$('div').remove("#"+item_b);
	$("#"+item_b).remove();
		$.ajax({
    type: "POST",
    url: "plugin/delete_image.php",
    data: "filepath="+item_a,
    success: function(){
    alert( item_b+" Deleted");
}
});
}

Thanks for any help at all,

Take care

1
Contributor
1
Reply
3
Views
7 Years
Discussion Span
Last Post by cjay175
0

Ok so finally, after a ton of variations I got it to work.
Instead of this... $("#"+item_b).remove(); This works though... $("div[id='" +item_b+ "']").remove(); I also tried a few variations of the following (change the quotes) $("#' +fname+ '") without success.

Would this be because of the variable I'm using for the selector or am I doing somehting dumb with quotes,

Thanks,

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.