jquery - Uncaught ReferenceError: .parent() or closest() -


within loop, multiple divs 1 below appears.

<div id="author-id-3" class="follow-me">                              <div class="author-follow">     <a id="3" class="meta-badge"><span class="icon-close"></span> follow</a>     </div>           </div> 

i use ajax update data within db.

jquery('.author-follow').on('click', '.meta-badge', function(e) {      e.preventdefault();                           var user_id         = $('.author-follow a.meta-badge').attr('id');        $.ajax( {         ...                              beforesend: function() {             $('.follow-me .author-follow').fadeout( 'fast' );             $( '<div class="icon-loading"></div>' ).hide().appendto('.follow-me').fadein( 'slow' );          },         success: function( data ) {             $('.follow-me .icon-loading').remove();             $('.follow-me').html( ajax_setting.ajax_follow_success ).hide().fadein( 'slow' );              console.log( user_id );         }      } )   }); 

this causes follow-me divs get's updated ajax_follow_success function when particular button clicked on page. while should appear within specific button area.

i tried using:

$toggle = $(this).parent().parent().find('follow-me');  beforesend: function() {     $toggle.fadeout( 'fast' );     $( '<div class="icon-loading"></div>' ).hide().appendto($toggle).fadein( 'slow' );   }, 

but got uncaught referenceerror: $toggle not defined

i tried closest() doesn't quite work (most because don't use properly).

beforesend: function() {     $(this).closest('.author-follow').fadeout( 'fast' );         $( '<div class="icon-loading"></div>' ).hide().appendto( $(this).closest('.follow-me') ).fadein( 'slow' );   }, 

any in putting me on right track appreciated.

edit:

i approached different angle (without success).

var div_id          = $('.follow-me').attr('id');  beforesend: function() {                 $('#' + div_id + ' .author-follow').fadeout( 'fast' );                       $( '<div class="icon-loading"></div>' ).hide().appendto('#' + div_id + '').fadein( 'slow' ); console.log( div_id  );                          }, 

you missed . character in class .find('follow-me') means searching tag follow-me not class.

$toggle = $(this).parent().parent().find('.follow-me'); //                                        ^ use '.follow-me' 

Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -