$(document).ready(function() {
$("#register button[name=btnPosta]").click(function() {
console.log('clicked');
thisBtn = $(this);
parent = $(this).parent();
name = parent.data('name');
$(this).attr('disabled', true);
$.post('register.php', {
name: ('name')
}, function(data) {
console.log('Ajax success');
parent.next('#message').html(data);
thisBtn.attr('disabled', false); // reset });
console.log('Ajax success');
});
});
});
This function is used to display name in the #message div
however nothing gets displayed in the div.
Assuming your markup is similar to the markup you posted in your duplicate post from an hour ago:
The problem is in your use of
.next(). When you pass a selector argument to.next(), you only get a result if the next sibling element matches the selector. Your call toparent.next("#message")returns an empty jQuery object because:<td>) does not have an id ofmessage.<td>.Since
parent.next("#message")returns an empty jQuery object, calling.html()on it has no effect. The solution is just to use$("#message")directly:My original answer was just a red herring:
Make sure to use the
varkeyword when defining your variables. Withoutvar, you are creating a property on theGlobalobject (orwindowwhen running JavaScript inside a browser). But,parentis already a property ofwindow. In IE,window.parentis read-only, so your value is never set and you will get an error when you callparent.data().Your code works for me when I use
var: http://jsfiddle.net/gilly3/MkS9X/