Skip Navigation

[Resolved] javascript within a view

This support ticket is created 3 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

This topic contains 1 reply, has 2 voices.

Last updated by Jamal 3 years, 7 months ago.

Assisted by: Jamal.

Author
Posts
#2064691
Screen Shot 2021-05-21 at 3.54.27 PM.png

I have a view that filters results ....

I am trying to drop this little hide a div code in. which uses javascript. it works fine except after i filter something the javascript stops working ...

I am putting the javascript in the JS editor box in the Search and Pagination area.

html:

<div class="panel panel-default col-sm-6" style="text-align:center;">
<div class="panel-heading">Toggel Data</div>
<div class = "panel-body">
<h2 id="hide4">welcome to all</h2>
<button type="button" class="btn btn-primary" id="btn3">Click To Toggle</button>
</div>
</div>

js:

$("#btn3").click(function(){
$("#hide4").toggle('slow');
});

#2065103

Hello and thank you for contacting the Toolset support.

This most probably because you are using AJAX in the view. Once the search pagination completes, Toolset updates the filters with new ones, which means that the old code will not get executed for the button that was added again after the search or pagination.
https://toolset.com/documentation/programmer-reference/adding-custom-javascript-code-to-views-that-use-ajax/

Try this instead:

jQuery( document ).on( 'ready js_event_wpv_pagination_completed js_event_wpv_parametric_search_form_updated', function( event, data ) {
	$("#btn3").click(function(){
                $("#hide4").toggle('slow');
        });
});

I hope this helps. Let me know if you have any questions.