views:

347

answers:

7

I have an application that has this format scattered around but I dont know what kind it is. It's not jQuery, so what is it?

$('some_edit').style.display  = "block";
$('some_views').style.display = "none";

I get this in firebug and I know the element is present:

$("some_edit").style is undefined
A: 

It's JQuery -- uses $ as its key variable.

Added:

Could also be mootools. Also uses $

Added:

'some_edit' would be the id of an element.

ps. I agree $ could be anything. Odds are though that it is JQuery or Mootools. "When you hear hoof beats, think horses, not zebras."

Larry K
What kind of selector is `'some_edit'`?
Dominic Rodger
Many libraries use $ as a helper variable, it's certainly not jQuery specific.
Marek Karbarz
Not neccessarily - Many libraries uses $, but I will agree that JQuery is the likely library (as it has the most widespread adoption)
driis
its an id element
Matt
@driis - jQuery uses css type selectors. $('some_edit') is not a valid jquery selector... unless the page has a node called "some_edit". If it were an id it would be "#some_edit". If its a class, then ".some_edit".
Dale
Re @driis. Whoops, me bad. Thanks.
Larry K
It could also be prototype.
Pekka
+14  A: 

It could be many things - examine the source code (or use Firebug) and see what JS libraries are being loaded.

Marek Karbarz
+1 - by far the most sensible answer
Dominic Rodger
If you're going to use Firebug, may as well set a breakpoint and step into it just to be doubly sure which library is being executed.
nirvdrum
+11  A: 

A lot of people have defined the '$' symbol as a substitute for document.getElementById().

Basically:

function $(id) { return document.getElementById(id); }
$("ElementID").innerHTML = "Text"; //Usage

A more proper, "namespace" example:

var DOM = { // creating the namespace "DOM"
    $: (function() {
        if(document.getElementById)
            return function(id){ return document.getElementById(id); }
        else if(document.all)
            return function(id) { return document.all[id]; }
        else
            return function(id) { /* I don't even want to get into document.layers */ }
    })()
};

// Later in the code:
{
    function ExampleFunction() {
        // ...
        DOM.$("ElementID").style.backgroundColor = "#96d0a0"; // a nice minty green color
        // ...
    }
}

I have used a self-invocation pattern (function(){ ... }()) in this example.

palswim
This is most likely the situation.
Stefan Kendall
Neat idea... I don't do a lot of JavaScript, but I might just use this little shortcut next time around. +1
iandisme
lol. please don't. thinking like that from everyone that ever did any js release is what causes framework compatibility issues these days. namespace!
Dimitar Christoff
For complete answer, provide the namespace option for folks :)
Mark Schultheiss
A: 

Look in the head section of the page for the link to the js file and update your question with the file name.

Looks like bad jQuery code to me :)

subt13
Firebug would be preferable to "view source"
Stefan Kendall
Not everyone uses firefox or firebug.
subt13
A: 

It is setting the display style for the two page elements - the display property specifies the type of box an element should generate.

block = The element will generate a block box (a line break before and after the element) none = The element will generate no box at all

RandomNoob
+3  A: 

at first i thought the jquery selector would likely have been $("#some_edit") and then .css(). so I would have said, prototype or mootools or a home brew $.

you can certainly discount both mootools and prototype, because if the selector returns an object, then the style property will be available (ignoring best practices in both frameworks on setting styles).

this leaves, the site uses homebrew $ assignment or jquery, which is not being used correctly.

actually, $("foo").style.blah in jquery will produce this very exception (even if the selector was good) - here is jsfiddle to the rescue

case point jquery (triggers): http://www.jsfiddle.net/dimitar/vmsZn/

case point prototype (works): http://www.jsfiddle.net/dimitar/vmsZn/1/

case point mootools (works): http://www.jsfiddle.net/dimitar/vmsZn/2/

Dimitar Christoff
A: 

Put a [0] in front of $('some_views') to return the Native DOM Element.

$('some_views')[0].style.display = "none";

or $('some_views').get(0).style.display = "none";

or $('some_views').css('display', 'none') to iterate through the collection of DOM elements.

John Strickler