jQuery Codes for javascript

1

I am having problems, Javascript is very confusing for me, let's see that I have a function that accomplishes all this in jQuery

$(".message-form-content").attr('style', ' '); // Esvazia o style da div
$("#load-content").html(success); // Preenche com o sucess da funcao
$("#imageForm").reset(); // Reseta o formulario
$("#post9999999999").val(''); // da empty na textarea
$("#post9999999999").focus(); // Focaliza na textarea
$("#queued-files").html("0"); // Poe valor 0
$(".selected-files").fadeOut(600); // Desaparece em fadeout
$("div.timeago").timeago(); // Renove
return true;  

I need to turn all this into Javascript, because in the file where the function is pulled there can not exist jQuery

    
asked by anonymous 13.12.2014 / 17:40

2 answers

6

Ok ... here you go, because Christmas is right there at the door:)

  

$ ("message-form-content"). attr ('style', '');

var elementos = document.querySelectorAll(".message-form-content");
for (var i = 0; i < elementos.length; i++){
    elementos[i].style = '';
}
  

$ ("# load-content"). html (success);

document.getElementById('load-content').innerHTML = success;
  

$ ("# imageForm"). reset ();

document.getElementById('imageForm').reset();
  

$ ("# post9999999999"). val ('');

document.getElementById('post9999999999').value = ''; 

$ ("# post9999999999"). focus ();

document.getElementById('post9999999999').focus();
  

$ ("# queued-files"). html ("0");

document.getElementById('queued-files').innerHTML = "0";
// repare que assim como tinha é string, pode tamber fazer .innerHTML = "0" para ter Type Number
  

$ ("selected-files"). fadeOut (600);

Note: can (and should!) do this with CSS, there are already answers about this here in SOpt. But in JS I think there is no live example: link .

var elementos = document.querySelectorAll('.selected-files');
for (var i = 0; i < elementos.length; i++) {
    elementos[i].style.opacity = 1;
    fade(elementos[i], 600);
}

function fade(el, duracao) {
    if ((el.style.opacity -= 40 / duracao) < 0) el.style.display = "none";
    else setTimeout(function () {
        fade(el, duracao);
    }, 40);
}
  

$ ("div.timeago"). timeago ();

This one has to ask a separate question :) You have to explain better what plugin it is and what function it does.

    
13.12.2014 / 18:29
3

Friend, I do not think anyone will convert all this to you.

Many of the things that jQuery does is actually very simple to do with just Javascript.

Here are some pages to search for:

  • youmightnotneedjquery.com
  • github.com/jquery/jquery (jQuery source code)
  • github.com/mootools/mootools-core (MooTools source code)

I particularly enjoy browsing the source code of certain libraries, and I often find myself amazed at how simple it is to do certain things.

    
13.12.2014 / 18:13