SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Knowledge is key 2 progression Tryst's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Applying styles to returned Node with firstChild

    Hi all,

    I would like to get the first child of a HTML element and apply a style to it, but I can't figure out how to do it. As far as I can see I can only change its value, and the firstChild only has the following properties, so cant really set a style...

    ElementType = bodyElement.nodeType;
    elementName = bodyElement.nodeName;
    elementContent = bodyElement.firstChild.nodeValue;

    Hope you can help me here

    Thanks

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,179
    Mentioned
    191 Post(s)
    Tagged
    2 Thread(s)

    styling

    Once the script "hooks" to the element, eg.
    Code JavaScript:
    var want_to_change_style = document.getElementById('target_elem');
    you should be able to style it something like this
    Code JavaScript:
    want_to_change_style.style.color = "#811400";
    want_to_change_style.style.textDecoration = "underline";
    want_to_change_style.style.marginLeft = "2em";

  3. #3
    Knowledge is key 2 progression Tryst's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But thats my issue, I don't have the ID of the element I want to style. I have an elementID, but its one of the child. I want the ID of the 'parentNode'.

    Thanks

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,179
    Mentioned
    191 Post(s)
    Tagged
    2 Thread(s)

    style parent node

    Can you do something like this
    Code JavaScript:
    var target_child = document.getElementById('target_elem');
    var target_parent = target_child.parentNode;
    target_parent.style.color = "#811400";


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •