I'm having trouble with jQuery not recognising elements on my page and throwing an error saying the elements I'm trying to select are null.
We are inserting our content into the following wrapper, which is supplied by the client:
http://www.ft.com/global/mm0802/ag/wrapper
The wrapper contains the following string:
<!-- ftplchol id="contentFixed" version="1.0" -->
which we replace with our content and then render the page.
This is a sample of our content: (the problem I'm having is described below it)
<script src="/Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function () {
$('.ActionControl a').live("click", function () {
$.get($(this).attr("href"), {}, function (result) {
// do stuff with result
});
}, "html");
return false;
});
});
</script>
<div class="ActionControl">
<span>Fund Directory</span>
<span>
<a href="/funddirectory/DirectoryResult">A</a>
</span>
<span>
<a href="/funddirectory/DirectoryResult/B">B</a>
</span>
<span>
<a href="/funddirectory/DirectoryResult/C">C</a>
</span>
</div>
When I run my stuff outside the context of the wrapper, everything is fine. My code behaves as expected. But when I run the full page with our content inserted into the wrapper, the following line throws an error:
$('.ActionControl a').live("click", function () {
saying that $('.ActionControl a')
is null. Specifically: Microsoft JScript runtime error: 'null' is null or not an object
It doesn't make any sense though. $('.ActionControl a')
couldn't and shouldn't be null because by the time the document is ready, <div class="ActionControl">
definitely exists on the page and it works when I don't use the wrapper. I can see it with FireBug & the IE Dev toolbar.
Even if I try to get something like $('a')
or $('div')
(of which there are many on the page), it still throws the same error. I know jQuery is working though because the $(document).ready()
function works..
Does anyone have any idea why this wouldn't be working? Is there something in the wrapper that would prevent it from seeing my control, or any other controls?