[jQuery] jQuery selectors with reference to object

[jQuery] jQuery selectors with reference to object


Hi, I am new to jQuery and is curious if this code can be shortened
down? It feels like it can, but I couldn't find any way to use jQuery
selectors if I have a specific reference to a object.
What I want to do is to find the element to the parent of "el" that
the id starts with linecolorbox. I know how to do it if I want to find
ALL the ones that id start with linecolorbox, but not if I want to
start with a specific element as reference (el.parentNode).
        jQ('.linecolor').each(
            function() {
                try {
                    var el = this;
                    if(el.value.match(/^f{6}$/i)) {
                        el.value = '';
                    }
                    var nodes = el.parentNode.childNodes;
                    for(var i=0; i<nodes.length; i++) {
                        for(var j=0; j<nodes[i].childNodes.length; j++) {
                            if(nodes[i].childNodes[j].id) {
                                if(nodes[i].childNodes[j].id.match(/^linecolorbox/)) {
                                    var colorbox = nodes[i].childNodes[j];
                                    if(el.value.match(/^[0-9a-f]{6}$/i)) {
                                        colorbox.innerHTML = '&nbsp;&nbsp;&nbsp;&nbsp;';
                                    } else {
                                        colorbox.innerHTML = '&nbsp;X&nbsp;';
                                    }
                                }
                            }
                        }
                    }
                } catch(e) {
                    alert(e.message);
                }
            }
        );