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>
    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?
    TheDataPlanet.com, Dec 18, 2016 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Likes Received:
    Best Answers:
    Trophy Points:
    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

    Likes Received:
    Best Answers:
    Trophy Points:
    qwikad.com, Dec 21, 2016 IP