Help with a jQuery issue please?

Conor

Elite Member
Joined
Nov 7, 2012
Messages
3,621
Reaction score
6,217
This script doesn't work in Wordpress, and I can't figure out why.

Code:
jQuery(".form input").change(function() {
$('.content p:contains("Custom Text")').hide();
});

Whenever a form input is modified, I would like to check if certain text exists in an element, and hide that element if the text is found.

I get an unhelpful "Uncaught TypeError: undefined is not a function" for some reason.
 
Wrap your jQuery code in this:
Code:
jQuery(document).ready(function ($) {

// your code

});
 
try this

Code:
function($){ 
	$(".form input").change(function() {
		$('.content p:contains("Custom Text")').hide();
	});
})(jQuery)
 
Thanks for the responses so far guys. I should have mentioned that I have tried noconflicting the jquery in every possible way I could think of. While it did get rid of the error, it didn't do anything for the functionality of the script.

What's confusing me is the fact that this code works:

Code:
jQuery(".form input").change(function($) {
alert('Changed');
});

and this code works:
Code:
jQuery(document).ready(function ($) {
$('.content p:contains("Custom Text")').hide();
});

But they don't work when I combine them.


I invite anyone to try the same thing on any Wordpress site, to see what I mean.
 
Last edited:
"...But they don't work when I combine them..."

Try this:
Code:
jQuery(document).ready(function ($) {
     $(".form input").change(function(){  
          $('.content p:contains("Custom Text")').hide();
     });
});
 
Last edited:
I managed to get an unnecessarily long piece of code working, if anyone is interested:

Code:
jQuery(document).ready(function ($) {
$('html').click(function () {
$('.content p:contains("Custom Text")').hide();
});


$('.form input[type="text"], .form textarea').on('input', function() {
setTimeout(function(){
$('.content p:contains("Custom Text")').hide();
}, 500);
});
});

I had to add the timeout function because there was other jquery firing before my code that apparently canceled the thing out.
 
Back
Top