<div class = "text_comments"> 
   <div class = "comment_item" style = "margin-left: 0px;">
     <div class = "service_text_comments_holder">
       <a href="http://fxposter.habrahabr.ru/" class="comments_nickname"> fxposter </a>
       ...
     </ div>
     <div class = "comment_text"> ... </ div>
     <div class = "comments_reply">
       <div class = "reply_word_holder" id = "reply_link866650"> (<a href="javascript:saw(866650);"> answer </a>) </ div>
         <div style = "display: none" id = "reply866650">
         <! - comment submission form ->
       </ div>
     </ div>
   </ div>
 </ div> )  <div class = "text_comments"> 
   <div class = "comment_item" style = "margin-left: 0px;">
     <div class = "service_text_comments_holder">
       <a href="http://fxposter.habrahabr.ru/" class="comments_nickname"> fxposter </a>
       ...
     </ div>
     <div class = "comment_text"> ... </ div>
     <div class = "comments_reply">
       <div class = "reply_word_holder" id = "reply_link866650"> (<a href="reply.php?comment_id=866650" class="show_reply_form" id="show_reply_form_866650"> reply </a>) </ div>
         <div style = "display: none" id = "reply866650">
         <! - comment submission form ->
       </ div>
     </ div>
   </ div>
 </ div> show_reply_form class and assign a function to the onclick event that would “open »Appropriate form.  function showForm (event) {
   var id = parseInt (this.id.replace ('show_reply_form_', ''));
   saw (id);
   return false;
 } this.id (i.e., the id of the current object), removes the “phrase” " show_reply_form_ " from it, thereby obtaining the number of the element that we need to open and calls the saw function, which was originally present in the HTML code. In order to avoid a redirect after clicking on the link, the function returns false .  $ ('. show_reply_form'). click (showForm);   $$ ('. show_reply_form'). invoke ('observe', 'click', showForm); this.id will be assigned to the id of this element (yes, this is “JavaScript magic” :)).  function showForm (event) {
   var id = parseInt (this.id.replace ('show_reply_form_', ''));
   saw (id);
   return false;
 }
 document.observe ("load", function (event) {
   $$ ('. show_reply_form'). invoke ('observe', 'click', showForm);
 }); window.onload event (when loading the page) using the observe function, which the document PrototypeJS object adds. observe adds to events that could already have been associated with the window.onload event, the event we specified. Try to use the addEventListener, observe (PrototypeJS) or $ (window) .load functions to prevent the substitution of functions already “hung” on an element.window.onload and element.onclick ) - this is the only time proper use of javascript.window.onload , but DOMContentLoaded . But I think that, for example, it would be clearer to use window.onload .Source: https://habr.com/ru/post/25991/
All Articles