SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: help with DOM

  1. #1
    SitePoint Zealot barleytwist's Avatar
    Join Date
    Dec 2005
    Location
    Lulworth, Dorset, UK
    Posts
    183
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help with DOM

    I am not a programmer and need to style something.
    The html with js entered parts is:
    <h5 class="trigger" title="Click for the rest">
    <a href="#"/>Read more ....
    </h5>
    The js which does this is:
    dc.templink.setAttribute('href','#');
    I want the result to be:
    a href="#">Readmore<</a>
    So then I can style the link with a:link, etc.
    Thanks.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    It's difficult to understand this question. Can it be rephrased in a more understandable manner?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Zealot barleytwist's Avatar
    Join Date
    Dec 2005
    Location
    Lulworth, Dorset, UK
    Posts
    183
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, it is a bit brief,

    Before the setAttribute the javascript is:

    dc.tempLink=document.creqateElement('a');

    So the javascript is writing the a element into an h5 area. Because the 'a' is being written on it's own without encompassing the "Readmore" text of the h5 tag I cannot seem to style the 'a' to provide the various link states. So I thought that if I put the 'a' around the h5 text I could achieve this. The example is at http://www.acdorchester.org/index.ph...=16&Itemid=213
    Look for the top right box called "Grandma". Thanks.

  4. #4
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    If you start off with this:
    HTML Code:
    <h5>Read more...</h5>
    and want this:
    HTML Code:
    <h5><a href="#">Read more...</a></h5>
    the first question is, why? The link isn't pointing anywhere! Are you seriously doing this just so that it responds to hover?

    Anyway, you can do it like this:
    Code javascript:
    // you need a reference to the h5 element in question
    var h5 = document.getElementsByTagName('h5')[0];
    dc.tempLink = document.createElement('a');
    dc.tempLink.setAttribute('href', '#');
    dc.tempLink.appendChild(h5.firstChild);
    h5.appendChild(dc.tempLink);
    However, please don't do this if all you want is to change the colour of the text when the user hovers over it! If that's what you're after, all you need to do is attach an onmouseover event to the h5 element and add/remove a class name to it. Then CSS can do its job and style it.

    Even that is a silly idea. The only browser that would even need that is IE6 and since this would not be a particularly crucial feature of the page, you could just forget about IE6 in this instance and let IE6 users see the ever so slightly more boring version.

    Also, you need to learn to explain yourself a bit better when you post on forums. This includes putting code needed to understand your problem in nice code blocks (like those in this post).


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
  •