How to validate ajax javascript function to check current element id in rails -
I am trying to figure out how a string is or in javascript, when one receives it. I have in my received.js.erb file;
$ ("# story_new "). FadeOut (); However, now I also want to play a different element that should get in such a way. Get.js.erb
$ ("# story_new "). Fade (); $ ("# Story_siv" lt;% = @ story.id% & gt; ") Fade (); However, only one Ajax call will be available at the time. I thought maybe a if statement works, but it does not know where to start with it. Some with lines; var story_new = "# story_new and lt;% = @ story.id%>"; Var story_save = "# story_save <% = @ story.id%>"; If ........ story_new $ ("# story_new
It does not make sense, because JS will not fail, if the selector does not get any element, but if you still want to see the element's existence, then you can do it with the following code:
var story_new = $ ("# story_new and lt;% = @ story.id%>"); Var story_save = $ ("# story_save <% = @ story.id%>"); If (story_new.length) story_new.fadeOut (); Else if (story_save.length) story_save.fadeOut ();
Comments
Post a Comment