0

I'm a complete newbie to magento so excuse me if this is a silly question. I need to add some code for a toggle function so something like this :

<script type="text/javascript">
 $("#Category1").click(function(){
  $(".moreCategory1").toggle();
 });
</script>

I need to add this to a static block so I tried adding it just at the end of the static block as usually I'd add it to the end of the body or the footer, but it doesn't work. So where would I need to put the jquery code for a static block?

Marius
199k55 gold badges431 silver badges837 bronze badges
asked Mar 15, 2016 at 13:43

2 Answers 2

1

Likely you are having a conflict with prototype.js. You can do as Marius pointed out and use prototype which is already used throughout Magento, or if you'd like to use jquery, you can use a noconflict. You could also just replace you '$' with 'jQuery' to avoid conflict.

<script type="text/javascript">
 jQuery("#Category1").click(function(){
 jQuery(".moreCategory1").toggle();
 });
</script>
answered Mar 15, 2016 at 14:51
0

Why do you need jquery for simple tasks. Use prototype and it should work nicely:

<script type="text/javascript">
 $('Category1').observe('click', function() {
 $$('.moreCategory1').each(function(item) {
 $(item).toggle();
 })
 })
</script>
answered Mar 15, 2016 at 13:53

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.