0

I have some strange comportement with my ajax request. The ajax request processes correctly, and the callback function removes a class 'invisible', that reveals a hidden div. In this div, I target an element with a "target" id. But quite strangely, when I want to add a text inside the div with an $("#target").text('hello'); most of my webpage disappears. A wrong syntax ? Any idea ?

Best, Newben

3
  • What is contained in target by default? Commented Jun 27, 2012 at 23:49
  • it sounds that the div has been closed in a wrong way and wraps unwanted elements. try #target {background-color: red} Commented Jun 27, 2012 at 23:54
  • Provide a fiddle for best answers. Commented Jun 27, 2012 at 23:55

1 Answer 1

2

Try $("#target").html('hello');

Sign up to request clarification or add additional context in comments.

4 Comments

@zerkms Darn jQuery always trips me up, too used to vanilla JS.
Right, in fact I had in my call back function an append method that wa called after the $("#target").text('hello'), so by switching it, it works now !! But since I am really not familiar to jquery, I have another issue : "target" is an id of a p tag that corresponds to a comment. So, if I want to have a unique comment text each time the user triggers the comment button, I must do an : var target = $('.target').last(); and then $(targetting).text(comment); but it doesn't work. Anybody has an idea ?
sorry i didn't precise that I changed target into a class to prevent uniqueness conflict :)
@Newben glad it helped. please upvote and/or accept the answer if it solved your problem. also, if you have other questions dont hesitate to create a new question :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.