-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJS-JQuery.js
56 lines (44 loc) · 1.22 KB
/
JS-JQuery.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/***********
JS - jQuery
***********/
//CARGAR UNA FUNCION AL CARGAR UNA PÁGINA
//JS
window.addEventListener('load', init);
function init(){}
//jQuery
$(function(){});
$(document).ready(function(){}); //¿? no estoy 100% seguro
//SELECCIONAR ELEMENTOS
//JS método1
document.querySelector('#elemento');
//JS método2
document.getElementById('elemento');
//jQuery
//DATASET
//Leer JS
var elementos = document.querySelectorAll('[data-atributo]');
//Leer jQuery
//escribir JS
elementos.dataset.a = "nuevo valor";
//escribir jQuery
$('#elementos').data('atributo','nuevo valor');
//CREAR ELEMENTOS
//JS
var target = document.getElementById('contenido');
var imagen = document.createElement('img');
imagen.setAttribute('src','img/1.jpg');
target.appendChild(imagen);
//jQuery
//MANEJAR EVENTOS
//JS método1
elemento.addEventListener('click', function(){});
//JS método2
elemento.onclick = function(){};
//jQuery
//AÑADIR,QUITAR,SABER SI TIENE UNA CLASE CSS, Y PERMUTAR CLASE CSS DE UN ELEMENTO
//JS
elemento.classlist.add('rojo'); //se pueden añadir varias separandolas por comas
elemento.classlist.remove('rojo');
if(elemento.classList.contains('rojo')){}
elemento.classList.toggle('rojo');
//jQuery