I have this chunk of code in my coffeescript:
$('.asdasd').ready ->
$.ajax '/splunk/100000000',
type: 'GET'
cache: false
success: (html) ->
$('.splunk_results').append html
The asdasd div doesn’t even exist — however, in my console, I can see a call to /splunk/10000000″ being made. Why is this happening?
EDIT:
I think the issue might have to do with the fact that the div in question isn’t loaded with the initial page — the page is full of partials, and the div is only loaded with the click on another js button that modifies the DOM. I basically want to see when that div exists, and when it does, make a new request and populate the div with the results of that request.
(heavily edited in response to question edit)
.readyis only a valid event for document. jQuery’s documentation forreadydoesn’t define behavior for cases where the argument to$isn’tdocument. That said, there’s nothing stopping you from defining an event that acts the way you want! Rather than listening for the ready event, invent a custom event (say,readyForSplunk) and trigger it at the appropriate time.The document, or some nearer parent of the to-be-created
asdasddiv, should have a delegate handler listening for thereadyForSplunkevent. The js button that creates theasdasddiv should alsotriggerHandler('readyForSplunk')the new div.