I am trying to add a p-element from a responseText of an Ajax request.
Before adding, I would like to see if responseText already exists in the text of the parent div element, and not add it if it is. The problem is that I cannot get indexOf (responseText) to work using the responseText variable. My code works when I pass a string literal to indexOf.
Here is my code:
jQuery('#addButton').live('click', function () {
new Ajax('<url>', {
method: 'get',
dataType: 'html',
onSuccess: function (responseText) {
var text = jQuery('#div').text();
if (text.indexOf(responseText) == -1) {
jQuery('#div').append(responseText);
}
}
}).request();
})
Thanks in advance for any suggestions.
source
share