I've been trying for a few hours now to figure out why my jquery code does not work when added as a page in Wordpress.
As a standalone page everything works just fine but when converted to a Wordpress page jQuery click event does not fire anymore.
My jQuery code looks like this currently:
jQuery(document).ready(function() {
jQuery('button#convert').click(function() {
alert("test");
var text = jQuery('textarea#textInput').val();
var method = jQuery('select#methodOptions').val();
if (text!='')
{
$.ajax({
url: 'core/convert.php',
type: 'POST',
data: 'data=' + text + '&method='+ method,
dataType: 'html',
success: function( message) {
jQuery('textarea#textOutput').val(message);
}
});
}
});
});
My button looks like this in html
<button id="convert" class="convertbutton" type="button">Convert</button>
Also I can verify that the .js file that contains the above script is loading properly in the header and that also the jquery library is as well. Am I missing something ? Thanks in advance.
Edit: I found what the issue was, Wordpress was loading the jquery library in the footer where I was loading my .js in the header which was the reason the problem appeared since the library needs to be loaded before you call any scripts for obvious reasons.
Also $.ajax should be jQuery.ajax in noConflict mode.