Results 1 to 2 of 2

Thread: JavaScript to Change HTML Tag

  1. #1
    Join Date
    Jul 2006
    Posts
    249
    Rep Power
    0

    Default JavaScript to Change HTML Tag

    I want to make the click of a button run a javascript function that will change an html tag.

    Code:
    <script type="text/javascript">
    var type;
    var data = new Array();
    function getCookie(NameOfCookie)
    {
    
    if (document.cookie.length > 0) 
    { 
    
    begin = document.cookie.indexOf(NameOfCookie+"="); 
    if (begin != -1) // Note: != means "is not equal to"
    { 
    
    
    begin += NameOfCookie.length+1; 
    end = document.cookie.indexOf(";", begin);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(begin, end)); } 
    }
    return null; 
    }
    
    function getData(){
    //code to grab innerHTML of each p with class title "exceprt"
    }
    
    function changeTag()
    {
    if (type.length == 0)
    {
    type = getCookie("mode");
    }
    if(type == "list)
    {
    type = "grid";
    document.getElementsByClassName('excerpt').innerHTML = "";
    }
    else
    {
    type = "list";
    //to place code to replace innerHTML with string stored in data
    }
    }
            </script>
    
    <p class='excerpt'>
    <?php if (function_exists('smart_excerpt')) smart_excerpt(get_the_excerpt(), 55); ?>
    </p>
    At first I was thinking of just having the javascript change class name and have the css hide anything with the other name, but that wasn't working... any suggestions for that because that seems simpler to me.

    Please help.
    "And what's the real lesson? Don't leave things in the fridge"

  2. #2
    Join Date
    Jun 2007
    Posts
    678
    Rep Power
    0

    Default

    what do you want to change the tags to ?.... Provide more context


    As soon as you make something idiot proof, Nature makes better idiots!!!

    Think big, think smart, think linux

Tags for this Thread

Posting Permissions

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