Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jul 2011
    Toronto, ON
    Thanked 1 Time in 1 Post

    Hide a div using $(this).attr('id') not working

    Hi guys.

    I have a bunch of divs that have id's in the following format: <div id="cid183">. The id's are dynamically assigned so one might be cid183, cid195 etc and they are all unique values.

    I have a delete button in each div. When a user clicks this delete button i run some ajax which successfully removes some info from the db, but then I want to simply fade out the div. The delete button has an id that contains some other irrelvant information and then the id of the div to be removed in this format: <span class="delete" id="u544-183">delete</span> - the value of 183 corresponds to the div name cid183.

    The ajax is working as the information is being removed from my db properly, but the div won't disappear. Here is the relevant code:

    $('.delete').click(function() {
    		type: 'get',
    		url: '../delete.php',
    		data: 'ajax=1&delete=' + $(this).attr('id'),
    		success: function() {
    			var myid = $(this).attr('id');
    			var startsub =  myid.indexOf('-')+1;
    			var toremove = myid.substring(startsub);
    <div id="cid183">
        This is the content of the div
        <span class="delete" id="u544-183">delete</span>
    I'm guessing it's messing up in my indexOf, substring stuff....I don't really know.

    Sorry for the noob question!!!
    Last edited by inchecksolution; 01-28-2012 at 11:22 PM.

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Halle (Saale), Germany
    Thanked 981 Times in 954 Posts
    You don’t need all that crap. Just call
    Or, ideally, you would actually remove the element:
    $(this).parent().fadeOut(function() {


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts