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

  • How to add the dynamic new rows from my registration form in my database?
  • Issue in payment form gateway
  • How to create a facet for WP gridbuilder that displays both parent and child custom fields?
  • Function in anonymous Laravel Blade component
  • How to change woocomerce or full wordpress currency with value from USD to AUD
  • General questions about creating a custom theme Moodle CMS
  • How to add logging to an abstract class in php
  • error 500 on IIS FastCGI but no clue despite multiple error loggings activated
  • Composer installation fails and reverts ./composer.json and ./composer.lock to original content
  • How to isolate PHP apps from each other on a local machine(Windows or Linux)?
  • Laravel: Using belongsToMany relationship with MongoDB
  • window.location.href redirects but is causing problems on the webpage
  • Key provided is shorter than 256 bits, only 64 bits provided
  • Laravel's whereBetween method not working with two timestamps
  • Implementing UUID as primary key in Laravel intermediate table

Related Questions in JQUERY

  • In Datatables, start value resets to 0, when column sorting
  • Bootstrap modal not showing at the desired position on a web page when the screen size is smaller
  • window.location.href redirects but is causing problems on the webpage
  • Using JQuery Date Slider
  • Storing selected language in localStorage
  • How to stop other divs from still showing when i click a different button?
  • Check multiple values with jQuery
  • Bootstrap component does not want to render in Datatables function
  • put white spaces when entering an amount moneytype symfony
  • Trouble accessing custom header in AJAX response using jQuery in Fiware Keyrock
  • I just cant make it work, HTML, JS and Firebase error
  • Didn't declared variable still not getting any error in JavaScript
  • Move element horizontally while scrolling vertically in pure JavaScript
  • allow multi carousel in same page
  • Embedded TikTok posts / thumbnail styling issue

Related Questions in WHILE-LOOP

  • Reversing a number in Python
  • Not clicking when user presses mouse button
  • How to make a loop, repeat a loop again for my nims
  • I am trying to make a Turtle Eater Game and I'm running into a minor bug(kind of)
  • I cant start the first loop again on python
  • Avoiding Loops in SQL, #temptables?
  • Better way to exit do-while loop?
  • While-loop in Python script not working when a record is added in MySQL table from triggers
  • Find lexicographically smallest palindrome for a given string
  • Why does it keep looping
  • Creating a WHILE-Loop with a dynamic number of conditions in Python
  • In Blazor server side app, I have endless while loop for consuming data from Kafka topic in my razor.cs page. How can I prevent it blocking the UI?
  • Getting stuck in Python while loop
  • I'm trying to write a simple program that picks a random number between 1 and 10 and gives the user to guess it
  • Recreating strncpy()

Related Questions in SHOW-HIDE

  • Show/hide text using getElementsByClassName for all classes
  • Button hide based on author in elementor
  • Excel VBA hide/Unhide Rows
  • Hide all elements when the one element is visible
  • How can I hide and show the menu well so that it doesn't look messed up?
  • Hide and show span element by clicking div element?
  • Hidden text boxes show on exporting SSRS report to Excel
  • How to show and hide password when click on eye icon using jQuery and also both the password (new and confirm) should be matched
  • Show Hide a div based on selected option value of a select using JS
  • How to Remove Class from Current and Add to Next Element with JS Only?
  • When I tap and immediately type, the UITextField freezes, but if I tap it then wait, type works
  • How to show and hide multiple divs as I click the respective button with only JavaScript?
  • Show/hide rows and sheets based on other cell values
  • How to hide pages in a streamlit multiple page app?
  • How to specify only the id of the appearing text, without specifying the ids of the hiding texts?

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 node.js arrays c asp.net json

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
  • Pricesm.com
  • Aftereffectstemplates
  • Jogjafile