Jenny
Jenny

Reputation: 919

Edit text within span tag with ID

I am having trouble with selecting the text within a span tag (this is in a template, I cannot edit the text directly), here is the HTML:

<table class="worf">
    <tbody>
        <tr>
            <td colspan="2" class="brown45">
                <span id="red24">Quantity and Pricing</span>

Here is what I tried:

<script>
    $('#red24').text('Confirm Your Reservation');
</script>

Upvotes: 1

Views: 94

Answers (2)

Despertaweb
Despertaweb

Reputation: 1820

Allways when the document is ready.

I think it'd be the best to use .html() you can use it just for a add text :

$('#red24').html('whathever');

or it'd be the best if you prefer to make it visible or with another style or class for instance :

$('#red24').html('<p class="foo"><b>Confirm Your Reservation</b></p>');

Upvotes: 0

James Donnelly
James Donnelly

Reputation: 128781

You need to wrap jQuery code in a $(document).ready() function:

<script>
    $(document).ready(function() {
        $('#red24').text('Confirm Your Reservation');
    });
</script>

Upvotes: 4

Related Questions