Gandalf StormCrow
Gandalf StormCrow

Reputation: 26222

Span doesn't get updated within div

Hello I'm trying to update div span text from ajax call, here is my html structure :

<div id="23" class="message product error">
        <strong>
            <br> 
            <strong>Unique id Id:</strong>
            <span class="uniqueId" style="color: #000; font-weight: bold;">job_201208311928_78749</span>
            <br> 
            <strong>Job Status:</strong> 
            <span class="status" style="color: #000; font-weight: bold;">IN PROGRESS</span>
</div>

I'm trying to update status IN PROGRESS to SHIPPED

But my jquery fails to do it :

function update (item){
    $('#' + item.id + "span.status").text(item.CurrentStatus);
}

Item.id and item.CurrentStatus both have right values when I alert.

Upvotes: 1

Views: 83

Answers (5)

phant0m
phant0m

Reputation: 16905

As already pointed out, you need to insert a space. This space indicates, that the <span> element with the class status is a descendant of the element with the given id.

Without the space, you're saying give me the element with the id <id>span (e.g. 23span) with the class status.

function update (item){ 
    $('#' + item.id + " span.status").text(item.CurrentStatus); 
} 

Upvotes: 0

Akhil Thayyil
Akhil Thayyil

Reputation: 9413

I think you missed a space in selector

Try this

 $('#' + item.id + " .status").text(item.CurrentStatus);

Upvotes: 0

Richard Neil Ilagan
Richard Neil Ilagan

Reputation: 14747

Gotta insert a space there.

$('#' + item.id + ' span.status').text(item.CurrentStatus);

Or to make it even clearer:

$('#' + item.id).find('span.status').text(item.CurrentStatus);

Upvotes: 3

jncraton
jncraton

Reputation: 9142

I believe that you need a space in your selector:

function update (item){
    $('#' + item.id + " span.status").text(item.CurrentStatus);
}

Upvotes: 1

JSK NS
JSK NS

Reputation: 3446

You need to include a space before your span:

function update (item){ 
    $('#' + item.id + " span.status").text(item.CurrentStatus); 
} 

Upvotes: 4

Related Questions