1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

jQuery closest() remove() on <a> doesn't work?

Discussion in 'jQuery' started by TheDataPlanet.com, Dec 18, 2016.

  1. #1
    Please see this page which has this code:

    <div class="pure-control-group query-brand-by-column">
      <!-- somethings else -->
      <div class="pure-u-1 pure-u-sm-1-24 control-group-sub">
      <a href="javascript:$(this).closest('.query-brand-by-column').remove();" class="pure-button danger">X</a>
      </div>
    </div>
    Code (markup):
    Clicking the X link should remove its ancestor div.query-brand-by-column as a whole but somehow it's not working. I've checked jQuery docs and this answer and the code seems absolutely all right to me but it simply doesn't work. Any idea?
    SEMrush
     
    TheDataPlanet.com, Dec 18, 2016 IP
    SEMrush
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,630
    Likes Received:
    724
    Best Answers:
    152
    Trophy Points:
    470
    #2
    Please, for the love of God, don't try to use inline jQuery. Put it in a proper function, in script tags or preferably an external js file.
     
    PoPSiCLe, Dec 18, 2016 IP
    sarahk likes this.
  3. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    5,870
    Likes Received:
    1,086
    Best Answers:
    22
    Trophy Points:
    400
    #3
    qwikad.com, Dec 21, 2016 IP