0
function showwLess() {
    button.style.display="block";
    idTab5.style="height:250px;overflow:hidden;font-size:14px;line-height:20px;";
    button2.style.display="none";
}

That is the code for my button, idTab5 is the div to be styled, I was wondering if there was a better way to apply the style to the div than

idTab5.style="

EDIT:

got this..

    <script>
var button2 = document.getElementById("button2");
var button = document.getElementById("button");
var idTab5 = document.getElementById("idTab5");
function showwMore() {
    $("#button").hide();
    $("#idTab5").css({height: "250px",
                   overflow: "hidden",
                   font-size: "14px",
                   line-height: "20px;"});
    $("#button2").show();
}

function showwLess() {
    $("#button").show();
    $("#idTab5").css({height: "250px",
                   overflow: "hidden",
                   font-size: "14px",
                   line-height: "20px;"});
    $("#button2").hide();
}
</script>

and

{if $product->description|count_characters:true > 350 } {* full description *}

<div id="idTab5" style="overflow:hidden;height:250px;font-size:14px;line-height:20px;">{$product->description}</div>
<input id="button" type="button" style="margin-top:5px;font-size:12px;line-height:16px;color:white; width:120px;background:#4e3248;border:none;height:30px;border-radius:5px;" value="Mostrar +" onclick="showwMore()">
<input id="button2" type="button" style="margin-top:5px;display:none;font-size:12px;line-height:16px;color:white; width:120px;background:#4e3248;border:none;height:30px;border-radius:5px;" value="Mostrar -" onclick="showwLess()">
{else}
<div id="idTab5" style="overflow:hidden;height:250px;font-size:14px;line-height:20px;line-height:16px;">{$product->description}</div>
{/if}
3
  • You could always learn jQuery and cut your code down significantly Commented Mar 10, 2014 at 22:57
  • 1
    Yes, use jQuery. Put the hammer and chisel away... we have a jackhammer to make that stone wheel. Commented Mar 10, 2014 at 22:58
  • 1
    orray orray thank you guys Commented Mar 10, 2014 at 23:00

2 Answers 2

2

There is, use jquery like this:

$("#idTab").css({
    height: 250,
    overflow: "hidden",
    //and so on...
});
Sign up to request clarification or add additional context in comments.

8 Comments

no, i think i didnt implement it correctly, i mean should it start? like: <script> and end </script> ??
sure, it is jquery code, you need to wrap it with script tag, and specify when it should be fired as well.
i edited my original post, you might want to take a look!, thanks in advance
it looks fine, but it will not style your buttons because you are not calling those function you have defined.
if you want to style them right away (though it does not seem to be the case) just do this call in your script: $(function() {showwMore();});
|
2

Use jquery. If your elements have id's:

function showwLess() {
    $("#button").show();
    $("#idTab5").css({height: "250px",
                   overflow: "hidden",
                   font-size: "14px",
                   line-height: "20px;"});
    $("#button2").hide();
}

It's really very easy to get used to it, if you want a starting point I highly recommend CodeSchool.

EDIT

Add this to your html to include the jquery library. I still recommend you check my links:

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>

4 Comments

how should it start? i mean like: script blak blak blak
i changed my original code for something like you posted and crashed, dont get it yet, sorry
Well, you first need to include the actual library. I believe it will be faster if you follow the CodeSchool link I provided, or try a tutorial (w3schools.com/jquery/jquery_install.asp), than me explaining everything here. Going further on how to get started with jquery would be a subject for another question (like this one: stackoverflow.com/questions/547384/…)
i did see it, tried to implement it, and still doesnt work, im almost 100% sure that im doing something wrong at the code since im pretty new at this think and dont know much, i edited my main post in chase you would like to see. thanks anyway

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.