DEVHIDE
  • Home (current)
  • About
  • Contact
  • Cookie
  • Home (current)
  • About
  • Contact
  • Cookie
  • Disclaimer
  • Privacy
  • TOS
Login Or Sign up

Trying to hide specific div in jquery in php while loop

368 Views Asked by Ryan D At 17 December 2016 at 22:33 2025-12-18T04:17:46.681939

I have this form being outputted from a PHP while loop :

echo '<div id="postCont" class="postCont'.$pid.'" style="block;">
    <div id="clLink">
      <a id="clLink" href="'.$plink.'" target="_blank"" title="'.$ptitle.'">'.$ptitle.'</a>
    </div>
    <div id="clDate">Posted on '.$pdate.'</div>
    <div id="clDesc">'.$pdesc.'</div>

    <form method="post" class="ibadForm">
        <input type="hidden" name="id" value="'.$pid.'">
        <input type="hidden" name="hiddenBad" value="yes">
        <input type="image" src="../img/bad.png" name="subBad" value="Bad" class="bad">
    </form>
</div>';

I am trying to remove the individual .postCont when the ibadForm is clicked with jquery.

$(".ibadForm").submit(function(e) {
     var url = "add_form.php"; 
     var id = <?php echo $pid?>;
     $.ajax({
          type: "POST",
          url: url,
          data: $(this).serialize(),
          success: function(data)
         {
             $('.postCont' + id).hide();
         }
     });
     e.preventDefault();
 });

It submits the form to add_form.php fine but doesn't hide the postCont. If I remove the id from the class then it hides all post Cont's. Can anyone tell me where I am going wrong?

php jquery while-loop show-hide
Original Q&A
1

There are 1 best solutions below

0
Zakaria Acharki Zakaria Acharki On 17 December 2016 at 22:34 BEST ANSWER

You could use closest() to get the parent div then hide it using hide() method like :

$(".ibadForm").submit(function(e) {
  var url = "add_form.php"; 
  var id = <?php echo $pid?>;
  var _this = $(this);

  $.ajax({
    type: "POST",
    url: url,
    data: $(this).serialize(),
    success: function(data)
    {
      _this.closest('.postCont').hide();
    }
  });
  e.preventDefault();
});

NOTE : You should store the $(this) object that refer to the clicked form in some variable (_this in my example) then use it inside the success callback since $(this) inside callback doesn't refer no more to the form, e.g :

_this.closest('.postCont').hide();

Hope this helps.

Related Questions in PHP

  • php Variable name must change in for loop
  • register_shutdown_function is not getting called
  • Query returning zero rows despite entries existing
  • Retrieving *number* pages by page id
  • Automatically closing tags in form input?
  • How to resize images with PHP PARSE SDK
  • how to send email from localhost using codeigniter?
  • Mariadb max Error while sending QUERY packet PID
  • Multiusers login redirect different page in php
  • Imaginary folder when I use "DirectoryIterator" in PHP?
  • CodeIgniter + XDebug: debug only working in the main controller, index() function
  • PHP script timeout when I use sleep()
  • posting javascript populated form to another php page
  • AJAX PHP - Reload div after submit
  • PHP : How can I check Array in array?

Related Questions in JQUERY

  • How to sort these using Javascript or Jquery Most effectively
  • Ajax jQuery firing multiple time display event for the same result
  • .hover() seems to overwrite .click()
  • Check for numeric value with optional commas javascript
  • Extending Highmaps Side Effect
  • Array appending after each onclick and loop in javascript
  • how can i append part of a table based on how many tr it has?
  • Play multiple audio files in a slider
  • Remove added set of rows
  • Access property of an object of type [Model] in JQuery
  • AJAX PHP - Reload div after submit
  • proengsoft/laravel-jsvalidation ReferenceError: jQuery is not defined
  • when a checkbox is checked how to display a different hidden element using javascript
  • Get jquery error Uncaught RangeError: Maximum call stack size exceeded
  • Removing only the closest thead on table filtering

Related Questions in WHILE-LOOP

  • Why does compiler recognize while(true) at compile time but not if(true)
  • Are the conditional statements if(true) and if(false) evaluated at compile time in java?
  • Merge two requests for searches
  • PHP While Foreach of MySQL key
  • loop for file location until file exists in bash
  • Display array items in groups
  • how to store strings in a while loop in java
  • while read line out of scope
  • CSV export only heading Arrays not Data
  • How to swap digits in java
  • while loop not looping / displaying count
  • Why this for loop doesn't do the same that the while loop?
  • counting characters in the input with while loop
  • Switch case (JavaScript) inside a while loop (PHP)
  • using getopts did not get the input value

Related Questions in SHOW-HIDE

  • Xpages hide panel / javascript
  • Hiding or Closing a Windows Form on C#
  • Span class with jQuery - show hide
  • Javascript show / hide on click multi ID
  • Show div when other div has display:block? NOT WORKING?
  • Show or hide a worksheet using a single button
  • Show imageview after click wait a moment then hide again [Android]
  • Jquery slidetoggle Show Hide One div at a time
  • Remove selected file from Input type = File in IE
  • How to hide an element after clicking it's child element using JavaScript
  • How to hide DIV in paging
  • Show and hide select input which is created dynamically
  • Use knockout to show or hide element by selected drop-down displayed text and not its value?
  • Can't hide content after it being visible. Also, how to shorten the code
  • Hiding markers Google Maps API v3 with a click

Trending Questions

  • UIImageView Frame Doesn't Reflect Constraints
  • Is it possible to use adb commands to click on a view by finding its ID?
  • How to create a new web character symbol recognizable by html/javascript?
  • Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
  • Heap Gives Page Fault
  • Connect ffmpeg to Visual Studio 2008
  • Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
  • How to avoid default initialization of objects in std::vector?
  • second argument of the command line arguments in a format other than char** argv or char* argv[]
  • How to improve efficiency of algorithm which generates next lexicographic permutation?
  • Navigating to the another actvity app getting crash in android
  • How to read the particular message format in android and store in sqlite database?
  • Resetting inventory status after order is cancelled
  • Efficiently compute powers of X in SSE/AVX
  • Insert into an external database using ajax and php : POST 500 (Internal Server Error)

Popular # Hahtags

javascript python java c# php android html jquery c++ css ios sql mysql r reactjs

Popular Questions

  • How do I undo the most recent local commits in Git?
  • How can I remove a specific item from an array in JavaScript?
  • How do I delete a Git branch locally and remotely?
  • Find all files containing a specific text (string) on Linux?
  • How do I revert a Git repository to a previous commit?
  • How do I create an HTML button that acts like a link?
  • How do I check out a remote Git branch?
  • How do I force "git pull" to overwrite local files?
  • How do I list all files of a directory?
  • How to check whether a string contains a substring in JavaScript?
  • How do I redirect to another webpage?
  • How can I iterate over rows in a Pandas DataFrame?
  • How do I convert a String to an int in Java?
  • Does Python have a string 'contains' substring method?
  • How do I check if a string contains a specific word?
.

Copyright © 2021 Jogjafile Inc.

  • Disclaimer
  • Privacy
  • TOS
  • Homegardensmart
  • Math
  • Aftereffectstemplates