Hello!

I am interested in the following question: How can js be used to display any information, but so that this information flies from JS, and not just show, for example, a div that has a display class: none ;? I, for example, derive, just in this way:

<input type="text" class="input-number"> <p style="display:none;" id="elem">Привет! Меня показывают и скрывают!</p> 

Js:

 $('.input-number').change(function() { $("#elem").fadeIn('slow'); setTimeout("$('#elem').fadeOut();", 2000); }); 

Here is an example - link

But this is displayed by adding a div on the site with the class display: none ;. So would not really want to. Is it possible to somehow generate JS for example? Like that:

 var tekst = '<p style="position:fixed;top:20px;right:20px;">Привет! Меня показывают и скрывают!</p>'; 

Those. write information to a variable and output it in the same way by changing the value in the input field. About this information is not found.

You can, of course, use the link , but again you must have a hidden div in the layout.

 <input type="text" class="input-number"> <div id="elem" style="display:none;"></div> 

Js:

 $('.input-number').change(function() { var tekst = '<p id="elem2" style="position:fixed;top:20px;right:20px;">Привет! Меня показывают и скрывают:)</p>'; $('#elem').html(tekst).fadeIn(); setTimeout("$('#elem').fadeOut();", 2000); }); 

I hope for your help :)

    1 answer 1

    Add your element to the body

     jQuery(document).ready(function($) { var msg = $('<p id="msg">Привет! Меня показывают и скрывают:)</p>'); $('body').append(msg); $('.input-number').change(function() { msg.fadeIn(); setTimeout(function() { msg.fadeOut(); }, 2000); }); }); 
     #msg { position: fixed; top: 20px; right: 20px; display: none; } 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="text" class="input-number"/> 

    • Thank! Fine! - Dmitriy
    • @ Dmitry If my answer solved your problem, mark it as correct - Anton Shchyrov
    • Yes, of course :) If you have time, please take a look, I have another question - link - Dmitry