The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Loop instead of loads of if / else statements

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #145943
    Preface Studios Ltd

    I’m using the following javascript (jquery) code at the moment:

    p>`if($h1p.mouseIsOver()) { $h1p.prev().css("background-color", $fullercolor_bg); } else { $h1p.prev().css("background-color", ""); } if($h2p.mouseIsOver()) { $h2p.prev().css("background-color", $fullercolor_bg); } else { $h2p.prev().css("background-color", ""); } if($h3p.mouseIsOver()) { $h3p.prev().css("background-color", $fullercolor_bg); } else { $h3p.prev().css("background-color", ""); }</p></p>
    <pre><code> etc` 

    I know there is some method which would make this easier and faster, like saying use h1,h2,h3,h4,h5,h6 and then loop through but I’ve been looking around and can’t find any examples I can work it out from.

    Could anyone help?

    If only CSS had a < parent selector! (I know it’s coming soon)

    Preface Studios Ltd

    I found this plugin: which as I understand the CSS4 spec should work with:

    !h4 + p

    but unfortunately it only works with the child selector >

    e.g. !p > a

    Preface Studios Ltd
Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.