关于jQuery之后

Suppose my HTML input looks like this :

<input type="text" class="hello">

I used jQuery and inserted element after it like this. AND it uses ajax

$(".hello").after("<p>"+response."</p>"); //response means things that come from ajax.

But after creates new element "<p>"+response."</p>" on every response...

How do I insert element jQuery class .hello so it get updated according to ajax instead of inserting "<p>"+response."</p>"..

I don't have any idea how to do it . :(

Regards

Given the description in your comment, it would be best to have a containing element which holds the response. You can then just overwrite its HTML on each request.

<input type="text" class="hello">
<p class="response-container"></p>
// in your AJAX success handler...
$(".hello").next('.response-container').html(response);

Try

//find the next element of .hello
var $p = $(".hello").next();
//if it is not a p element
if (!$p.is('p')) {
    //create a new p element and insert it after .hello
    $p = $('<p />').insertAfter('.hello');
}
//update its text
$p.text(response)

Maybe you need to have previously that response element o create just once.

<p class=".helloResponse">response</p>
<input type="text" class="hello">

$(".helloResponse").html(response);

Another way is to create the element first, but just once.

if($(".helloResponse").length ==0) {
$(".hello").after("<p class='helloResponse'>"+response +"</p>");
} else {
$(".helloResponse").html(response);
}