Please note this is not a direct answer to the question but I feel it would be useful for the OP and hopefully others
Whilst I most definitely aggree that in your case you can most simply use css to style your elements (please see @lennart's answer for example of child selection) there may be occassions when you need to be more dynamic when applying style, you can of course use jquery's .css() and similar functions, perhaps indeed use plain old javascript however this usually leads to dom traversal which can be fiddly even with jquery, the second option would be to dynamically add stylesheets which can also be quite effective, a third option would be to change/manipulate the <style> tag, for example you may have style defined in some json data where we can be a bit creative and build a string of css and add this to the <style>
// turn #accordion into a simple accordion menu
// adds style to the head from json data
$(document).ready(function() {
// hide <ul> nested in accordion
$('#accordion').find('ul').hide();
// add click event to accordion .heading
$('#accordion').find('.heading').click(function(e) {
// do not follow anchor
e.preventDefault();
// slide up any open sections
if(!($(this).hasClass('open'))) {
$('.open').removeClass('open').next().slideUp();
}
$(this).addClass('open').next().slideToggle();
});
// a function that parses json and
// appends it to <style>
function addStyleFromJson(json) {
// turn json into normal string
var style = JSON.stringify(json);
// remove apostrophes, colons before {, opening and closing {}
style = style.replace(/(")|(:(?=\{))|(^\{)|(\}$)/g, '');
// remove commas after }
style = style.replace(/(\}|\;),/g, function($0, $1){
return $1 ? $1 + '' : $0;
});
// prepend this style with any style declared in <head>
style = $('style').text() + style;
// append style element to head
$('style').text(style);
}
// load some style
$.ajax({
url: 'http://dl.dropbox.com/u/47426368/somejson.js',
dataType: 'jsonp',
jsonp: false,
jsonpCallback: 'myCallback',
cache: true,
success: addStyleFromJson
});
});
in this demonstration we turn html into an accordion style menu then load some json from a remote location and parse this into the <style> tag (presuming it is already there). As I have previously stated this may not be the best option and there are many options so as I said in my comment you must really learn this stuff in order to use it, it is no different from riding a bike or doing maths there is no magic just (hard)work and dedication :-), i hope that this demonstrates how you can use several technologies relatively simply to create something a bit more dynamically which I think was one of the reasons javascript came about
here is a demo