The WP version of jQuery already calls .noConflict(). This removes the usual mapping of $
to jQuery
. To add it back, use a no conflict wrapper:
(function( $ ) {
"use strict";
// javascript code here. i.e.: $(document).ready( function(){} );
})(jQuery);
Thank you for your response.
Can you check this?
Where is the mistake? It doesn’t work in a way I don’t understand.
Very strange. A very simple thing to do: hide the element. However, in WordPress this does not work.
(function( $ ) {
$(document).ready( function(){
$( "#button-W" ).click(function() {
$('.field-field-t').hide();
});
} );
})(jQuery);
I even want the direct element to start as hidden. This is the actual definition:
$('.field-field-t').hide();
I wrote the button for triggering later. I thought, “Do I need a trigger?” Of course it works in the browser as above.
-
This reply was modified 2 years, 6 months ago by loopforever.
-
This reply was modified 2 years, 6 months ago by loopforever.
Update:
From what I think it doesn’t work from the form structure.
I am working on a form. There are stages in the form:
Step-1
Step-2
…
So, there are splitters.
While going from Step-1 to Step-2, Next button is pressed. With this button, the other page opens and the HTML becomes visible. Probably JQuery isn’t working because it’s late here. Because the division I want to hide is in Step-3.
(document).ready definition exists as you can see. Also,
I got the js codes in the footer. What’s more, buttons (Next), as you might guess, are hard buttons. Therefore, it is impossible to write a Trigger. So, I changed the in_footer parameter in the wp_enqueue_script function. However, it didn’t work.
Do you have another solution?
-
This reply was modified 2 years, 6 months ago by loopforever.
-
This reply was modified 2 years, 6 months ago by loopforever.
I don’t see anything wrong with the script. To be sure, I tried it on my site, only changing the form field ID and class name to fit with my existing form. The click event was tied to a check box field, not a radio button, but I don’t see how that would matter. Clicking the box did hide the field with the matching class name, .field-field-t
in your case.
You said “With this button, the other page opens…”. Is this really a new page requested from the server? Or is it a “sub-page” that’s all part of the same thing, all loaded from the server at the same time? If it’s a new page, is your script being loaded on the correct page?
Check you browser console for any errors logged. An error from elsewhere can still affect your script even if it is 100% correct.
Verify that a script tag linking to your script file really exists in the page’s source HTML. If not, the file was not enqueued correctly.
Verify that the src attribute of the script tag really leads to your script file. Enqueuing with the wrong path is a common blunder.
Showing or hiding certain form elements based on user interaction is a common technique. Using .hide() alone wouldn’t allow the user to reverse course and make a different choice (other than by reloading the entire page). I assume you intend to implement this later once you are able to at least get something working to start with.
Thank you very much for your reply. I will consider these.