0

I have the following jQuery:

j(".refreshMe").html(html);

var something = $("li", html).length;

if ( something > 0 ) {
    j('.showlatest').slideDown();
}

and HTML:

<p class="showlatest"></p>

What I want to happen is,

if ( something > 0 ) {
    j('.showlatest').slideDown();
    ADD THE CONTENTS OF 'something' WITH THE TEXT 'NEW MESSAGES'
}

E.g.

<p class="showlatest">2 new messages</p>

I suppose I could define the 'New Messages' text as:

var newmessages = "New Messages";

But how can I then, in PHP speak, echo the results?

4
  • What's wrong with using $('.showlatest').html(something + ' new message')? Note, you should be using id instead of class if these are single things. The selectors will be more efficient. Commented Aug 27, 2010 at 19:37
  • 1
    I highly recommend that you change j to $ or $j. j will be used in nested for loops. Commented Aug 27, 2010 at 19:38
  • Even when using this: var j = jQuery.noConflict(); Commented Aug 27, 2010 at 19:42
  • Yes. Someone will write for (j = 0; j < something; j++). You should change that to var $j = jQuery.noConflict();. Unless you're already using a different $ library, you shouldn't do it at all. Commented Aug 27, 2010 at 19:46

1 Answer 1

6

You can call the .text() method to set the text of an element, like this:

j('.showlatest').text(something + ' New Messages');
Sign up to request clarification or add additional context in comments.

Comments

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.