keji
keji

Reputation: 5990

Why isn't .text or .html working

I have a span:

<span id="unreadbadge" class="badge red">0</span>

and a script that says on the executed function do this:

var arrayOfUnRead = jQuery.parseJSON(text);
jQuery("#unreadbadge").text(arrayOfUnRead.length);
confirm(arrayOfUnRead.length);

Though "1" the right value of arrayOfUnRead.length is called back from confirm the span with the id unreadbadge still remains with its same content "0". I have tried .html to and receive the same results. I am running this on Wordpress if that helps.

text is:

[{"id":"1","message":"Hello Users","conversation_id":"1","sender":"kdogisthebest","sent_on":"2013-03-12 13:45:58","read_by":"kdogisthebest"}]

Upvotes: 0

Views: 89

Answers (1)

Dylan Cross
Dylan Cross

Reputation: 5986

Try something like this:

var text = "[2,55,42]";
var arrayOfUnRead = $.parseJSON(text);
var lengthOfUnread = arrayOfUnRead.length;
$("#unreadbadge").text(lengthOfUnread);
confirm(lengthOfUnread);

Check out the fiddle: http://jsfiddle.net/LCCjB/

Upvotes: 1

Related Questions