Category Archives: JavaScript

Javascript/jQuery Debugging Tips

These are just some debugging tips that I always forget how to do, so I am writing them down here!

Testing your selectors 

In the browser console you can use jQuery to check the selectors you are using come back with the right thing! E.g.

console.log($(‘.class_name’).find(‘a’).html());

(Find what’s in the ‘a’ tag within this class or id)

What’s Coming Back in an Ajax Call?

To view what you have been sent from the server
Go to the dev tools in your browser, click on network tab, click on the relevant ajax link, then choose preview.
What is this thing?
console.log(thing.constructor.name)
Get the selected element
If you select an element in the browser, in the console you can access it with

$0
If you then call

dir($0)

It will return every attribute/property of that element.

 

More Chrome Tips

For lots more tips and tricks, check this out.

Leave a reply

JavaScript in Practice

Last week we were working on some Adwords scripts. Adwords scripts are JavaScript code you can write to customise actions or reports within your Adwords account – kind of halfway between using automated reports and the full on Google Adwords API.

In the Google Developers documentation I found heaps of examples of scripts you can use, and even better – they break the script down and explain how it works!  So, if you want to see JavaScript working in the wild (and particularly if you work in online advertising) – this will be very interesting for you.

For example, take this one – changing your ad bidding depending on the weather. Google gives you a script you can upload yourself into Adwords (although you would need a Wunderground API key – but then, it’s free so no probs). You do need to change some things in the script though, to specify the changes you want to make to the bids depending on the weather.

Apart from the awesomeness of free, pre-made, Google-approved scripts, what I love about this is that it gives me a chance to read some JavaScript which is doing things that I can actually use in my every day job. What makes it even better, for a budding programmer, is that it is a great teaching aid. Google takes you through the script step by step, teaching you how it works. It not only says what each part does, it also explains why certain functions were used.

Leave a reply