Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="es" dir="ltr">
- <head>
- <meta charset="utf-8">
- <title>JQUERY</title>
- </head>
- <style>
- .parrafo{
- background-color:#226677;
- }
- </style>
- <body>
- <h5>P Mostrar</h5>
- <p name="mostrar" class="parrafo">
- asdasdasdasdas
- </p>
- <h5>P sin attr name</h5>
- <p></p>
- <p id="datosrest"></p>
- <button name="actionBuscar">RUN</button>
- <button name="consumirRest">GET API utilizando AJAX Simplificado</button>
- <script src="js/jquery.js"></script>
- <script>
- /*
- $(selector).evento();
- */
- $(document).ready(function(){
- $("button[name='actionBuscar']").click(function(){
- texto = "Lorem Ipsum dolo sit at men";
- $("p[name='mostrar']").css("background-color","#445566").html(texto);
- });
- $("button[name='consumirRest']").click(function(){
- url_endpoint = "https://jsonplaceholder.typicode.com/posts";
- $.get(url_endpoint,function(datos){
- //console.log(datos);
- html = "";
- $.each(datos, function(k,v){
- html += "<strong>ID</strong>: "+v.id+"<br />";
- html += "<strong>Título</strong>: "+v.title+"<br />";
- });
- $("#datosrest").html(html);
- });
- });
- });
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement