I have:
mytext = jQuery('#usp-title').val(); then I do
if(jQuery("#datafetch h2 a").text() == mytext) { But one title could be:
Space Mission just as well as space mission
I cannot standardise the text format for other reasons therefore I am really looking at comparing two strings regardless of their capitalisation.
UPDATE
The thing is that I am using the input field as a search so the user could type space mission while the post title would be Space mission so the search result wouldn't be exact and i need the exact phrase instead.
Complete code:
<div id="datafetch"></div> function fetch(){ jQuery('#datafetch').empty(); mytext = jQuery('#usp-title').val(); jQuery.ajax({ url: '<?php echo admin_url('admin-ajax.php'); ?>', type: 'post', data: { action: 'data_fetch', exactwords: mytext }, success: function(data) { jQuery('#datafetch').html( data ); if(jQuery("#datafetch h2 a").text().toLowerCase().trim() == mytext.toLowerCase().trim()) { jQuery("#componi").attr("disabled", "disabled").hide(); } else { jQuery("#componi").removeAttr("disabled", "disabled").show(); } if(jQuery("#datafetch h2 a").text() != mytext) { jQuery("#fatto").hide(); jQuery('#datafetch').empty(); } } }); } It's trickier actually because the search is coming from the text input, so it's about the query of the ajax i believe more than capitalisation, just a thought. The latest code above gives no results by typing:
space mission while the post title is Space mission
UPDATE 2
Post article title:
Space Mission User searches for
space mission Console.log(data) gives correct result
<ul class="list-unstyled margin-top-80"> <li> <h2><a target="_blank" href="example.com"">Space Mission</a></h2> </li> </ul> Yet this doesn't happens:
jQuery('#datafetch').html( data ); if I insert the right words Space Mission does tho
String#toLowerCasedoes not work for you?