0

I want to replace the contents of the <div class="clicksAllTime"> but I cannot get it to work. The HTML below is part of a table. Each row has a different ID whch is a specific shortened url that im doing an ajax call on...

HTML:

<tr id="http://goo.gl/zxCR" class="shortenedUrl odd">
    <td class="center">
        <div class="clicksAllTime">
            <img src="../images/loading-gif-small.gif">
        </div>
    </td>
</tr>

JQUERY:

$('#http://goo.gl/zxCR.clicksAllTime').empty().append('<p>' + response[0].analytics.allTime.shortUrlClicks + '</p>');
Luke Bream
  • 855
  • 2
  • 10
  • 15

3 Answers3

1

Here's a selector that works. Am using html() to replace with text for demo so you can easily test

Working demo: http://jsfiddle.net/zKSGP/

 $('#http\\:\\/\\/goo\\.gl\\/zxCR .clicksAllTime').html('New Text')

Note spcae befor "clicksAllTime classs was missing in example. Also don't need to use empty().append(), just use html() it replaces all inside element

charlietfl
  • 170,828
  • 13
  • 121
  • 150
  • thanks very much for this. Your observation of the missing space was the main problem area. I have also done some server side processing to strip the `http://goo.gl/` off to make the id simpler. And it is now working! Thanks again – Luke Bream Mar 05 '12 at 15:20
0
    <html>
    <head>
    <meta charset="utf-8">
    <script src="http://code.jquery.com/jquery.min.js"></script>
    <script type="text/javascript">
    $(function() {
    $('.clicksAllTime').html('<p>' + response[0].analytics.allTime.shortUrlClicks + '</p>');
    });
    </script>
    </head>
    <body>
    <tr id="http://goo.gl/zxCR" class="shortenedUrl odd">
        <td class="center">
                <div class="clicksAllTime">
                        <img src="../images/loading-gif-small.gif">
                </div>
        </td>
    </tr>
    </body>
    </html>
t q
  • 4,593
  • 8
  • 56
  • 91
0

This may work.Just try bellow code / is treated as special characters.

$('#http:\\//goo.gl\\/zxCR.clicksAllTime').empty().append('<p>' + response[0].analytics.allTime.shortUrlClicks + '</p>');

check this CSS selector to select an id with a slash in the id name?

Community
  • 1
  • 1
siva565
  • 499
  • 2
  • 12
  • 25