开发者

JQuery passing Span Id to selector not finding element

I've done some searches and I think this should work but I guess I'm wrong. I'm using Ajax Manager inside a function.

My Js:

 function makeGetRequest2(wordId,docId) {
    var ajaxManager = $.manageAjax.create(开发者_C百科'cacheQueue', { queue: true, cacheResponse: true });
    //and add an ajaxrequest with the returned object
    ajaxManager.add({ success: function(html) {
            $('span[id="' + docId + '"]').text(' - Downloaded ' + html + ' time(s)');

         }, url: '/knb/GoogleAnalytic?docId=' + wordId
     });

 }

My HTML is generated by an XSL. It iterates several records, listed it in a table. Translated, the html looks like this snippet for 1 record :

"... Download File <img alt="download" border="0" style="margin:0px 0px; padding:0px;" src="page_white_put.png">
<script type="text/javascript">makeGetRequest2(escape('Title 2'),'book-3'); </script>
<span id="book-3"></span>.. " 

The idea is to make an ajax call and print out the results inside the span tag. The span id is variable (from 1 - however many records there are) and it is passed to the makeGetRequest2 function.

The ajax is successful, if I try to use the selector without variable, i.e. $('span[id="book-3"]').text() it works. But I am not finding it with the "+ docId +" for some reason. I've checked that the parameters have correct values.


Instead of:

$('span[id="' + docId + '"]')

you should use:

$('span#' + docId)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜