JavaScript Rails - how do I make sure a partial has been rendered in a js.erb

I am trying to bind a JS function to a text field (input of type "text"). Using JQuery 2.0.2 & Rails 3.1 I do this in a .js.coffee file located in assets/javascripts:

window.test_questions = {}
window.test_questions.bind_input = ->
  $('#question_content').on 'input', ->
    // do something

Then in a .js.erb located in the views\TheRightController folder I run:

$('#new_question').html('<%= escape_javascript(render("new_question_form")) %>');   
test_questions.bind_input();

#question_content does not exist on the page until the partial is rendered. I am worried that bind_input() will run before the render is complete, not find #question_content and bind nothing to it.

I am not 100% this is a problem (my code is working at the moment), but I am worried that if I use it elsewhere with a "heavier" render it will break.

Am I worried in vain? Is there any way to make sure the render is complete without errors, and only then execute the next line.

Answer:1

I have two pages ,let's say page1.aspx and page2.aspx . What i'm going to do is ,in page1.aspx i made a call to page2.aspx with window.open() javascript and pass the querystring ,and in page2.aspx (...

I have two pages ,let's say page1.aspx and page2.aspx . What i'm going to do is ,in page1.aspx i made a call to page2.aspx with window.open() javascript and pass the querystring ,and in page2.aspx (...

Working on jquery date picker in my current code. I want the datepicker should show from the year 1900 - till today date User has to select previous 10 years from today date if in case user select ...

Working on jquery date picker in my current code. I want the datepicker should show from the year 1900 - till today date User has to select previous 10 years from today date if in case user select ...

  1. vba user select date
  2. power bi user select date

I found that in JavaScript, switch is always a sentence of instruction and using it as an expression will give an error. So when I have to assign different values to a variable according to different ...

I found that in JavaScript, switch is always a sentence of instruction and using it as an expression will give an error. So when I have to assign different values to a variable according to different ...

I actually load an external JavaScript on my page this way: <script type='text/javascript' src='http://somedomain.com/somescript.php'></script> Note: it is a PHP file, but it produces ...

I actually load an external JavaScript on my page this way: <script type='text/javascript' src='http://somedomain.com/somescript.php'></script> Note: it is a PHP file, but it produces ...

  1. remove unwanted part of image online
  2. remove unwanted part of video
  3. remove unwanted part of image in photoshop
  4. remove unwanted parts from video online
  5. remove unwanted parts of a photo
  6. remove unwanted parts from a photo photoshop
  7. remove unwanted section breaks word
  8. how to remove unwanted part of video in vlc
  9. how to remove unwanted part of video in android
  10. how to remove unwanted part in photoshop
  11. process of removing unwanted part of an image
  12. process of removing unwanted part of an image is called