0

I have not a good Javascript knowledge, but I'm kinda good with jQuery though. I want to change some jQuery code to pure Javascript, but I have no idea how to do it.

$(document).ready(function() 
{
    $('#block').one('click', function()
    {
       $(this).val('{L_SEND_CONFIRM}').removeClass('button1');
       $('#replacement').val('{L_BLOCK_CODE}');
    });
});

Anyone willing to help me out please?

P.S: Sorry for asking such a dumb question, I really need to learn Javascript myself ASAP.

3
  • Why do you want to do that? And what have you tried already? Commented Aug 30, 2012 at 17:29
  • 1
    Are you trying to do this as a learning exercise or for a performance reason? jQuery just extends (and simplifies) JavaScript, but pure JavaScript and jQuery code can be mixed at will. Commented Aug 30, 2012 at 17:30
  • I've tried this: var block = document.getElementById('block'); function blacklist_click() { block.className = ''; block.innerHTML = '{LA_SEND_CONFIRM}'; document.getElementById('replacement').innerHTML = '{LA_BLOCK_CODE}'; }; block.addEventHandler('click', blacklist_click); block.attachEvent('onclick', blacklist_click); It didn't work. I need this Javascript instead of jQuery because of validation by a website, they don't like jQuery because it takes longer to load -.- Commented Aug 30, 2012 at 17:48

2 Answers 2

4

This is a rough equivalent (there are subtleties that if you want to address start getting annoying, thus the need for frameworks in the first place):

window.onload = function() {
    document.getElementById('block').onclick = function() {
        this.onclick = '';
        this.value = '{L_SEND_CONFIRM}';
        this.className = this.className.replace('button1','');
        document.getElementById('replacement').value = '{L_BLOCK_CODE}';
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

Unfortunately, the code you provided didn't work, it didn't change the value of my <input type="text... />. Any idea what could be wrong?
@Dugi: I typed getElementByID instead of getElementById. Try it now, should work. jsfiddle.net/hxbMg
0

onready and onload are two different beasts.

onready fires when the DOM is ready, but graphics may not have been loaded yet.

onload fires when everything needed, including graphics, have finished.

I like this library here to handle the onready stuff. It uses DOM methods for browsers that support it and uses a weird IE hack when it must:

https://github.com/ded/domready

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.