Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need some javascript help

    Code:
    <script>
    function clickPost(el){
    	var im=el.parentNode.style.backgroundImage;
    	var sp0=im.split("/");
    	var sp1=sp0[sp0.length-1].split(".");
    	document.getElementById("formInp").value=sp1[0];
    	document.F.submit();
    }
    </script>
    Code:
    <div class="thumb" style="background-image: url('images/1.jpg');"><a href='javascript:void(0)' onclick='clickPost(this)'>
    This code above snags the number from the background-image file, I changed my code around and I believe I need to go to a childnode now to grab the number from the img src but am having issues figuring it out. Thanks

    Below is the current code for displaying the thumbs:
    Code:
    <div id="container">
    <a href='javascript:void(0)' onclick='clickPost(this)'><div class="overlay"></div>
    <div class="image"><img src="images/2.jpg" /></a></div>
    </div>

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,396
    Thanks
    12
    Thanked 569 Times in 562 Posts
    This is illegal HTML
    Code:
    <div id="container">
      <a href='javascript:void(0)' onclick='clickPost(this)'>
        <div class="overlay"></div>
        <div class="image">
          <img src="images/2.jpg" />
      </a>
        </div>
    </div>
    An anchor is an inline element and must not contain block level elements. On top of that your element nesting is flawed.


  •  

    Posting Permissions

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