0

I'm developing an extension and I want to know how to hide an html element:

I tried this code, but it didn't work

$$('#myDiv').hide();

Where is my error?

6
  • Why are you using 2 $ signs? Commented Mar 19, 2014 at 9:48
  • 1
    why the tag magento removed? Commented Mar 19, 2014 at 9:53
  • 1
    $$ its magento using prototype.js not the real jquery and someone edited my question :( Commented Mar 19, 2014 at 10:04
  • 1
    what a mess! everyone editing the question without knowing the exact problem with added tags (magento) Commented Mar 19, 2014 at 10:08
  • 1
    yep the one who edited the quetion thinks i m idiot but he is !!!!! Commented Mar 19, 2014 at 10:10

5 Answers 5

4

In Jquery

$('#myDiv').hide(); //You have to include jquery library in your file

In Javascript

document.getElementById("myDiv").style.display = "none";
Sign up to request clarification or add additional context in comments.

Comments

1

Possible typo? Extra "$".

Jquery:

  $('#myDiv').hide();

And are you trying to do it on a click?

Comments

1

only one dollar sign needed

$('#myDiv').hide();

Comments

0

Initially this question was tagged .
So I assume the issue is inside a magento project.
Magento uses prototype by default.
In prototype you can hide an element like this.

$('element_id_here').hide();

$ means getElementById.

If you want to hide a set of elements, let's say with the class some_class do this:

$$('.some_class').each (function(elem){
    $(elem).hide();
})

it also works for ids the same way but it's kind of useless since the id must be unique in the page.

$$('#myDiv').each (function(elem){
    $(elem).hide();
})

4 Comments

ok @Marius thanks that worked the real issue is this question stackoverflow.com/questions/22475351/… ; do u have any idea because i m working with an idea that i don't think its a good one !!!!!!!!!!!!!!!!!
the $('element_id_here').hide(); give me that error Uncaught TypeError: Cannot call method 'hide' of null
This means that the element with id element_id_here does not exist
ok thats good solved with $$('#myDiv').each (function(elem){ $(elem).hide(); }) now i wanna insert an element how seems to me @Marius u r pro in magento :p
0

as when I first see this post it contains a tag. And many of the beginners do have problem with and in magento.

the code to hide html with id selector in jquery is:

$('#myDiv').hide(); //# for id selector

but for prototype, its:

$('myDiv').hide(); //no # needed for id selector

but even if it do not work then open web developer tool (Ctrl + Shift + C) of your browser and look for console tab. there you might be getting error.

Comments

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.