Search code examples
javascriptprototypejs

Javascript invoke hide and store string text as variable within LI tag


Using this question I was able to hide a list element that contained some string text. I'd like to re-use everything within these <LI></LI> tags however someplace else within the page. The entire contents of the LI tags can vary but will share the one common element I'm able to invoke the hide with. Is there some way to adjust this code to store everything found as a variable after I successfully hide it?

Event.observe(window, "load", function(){

$$("li:contains('Full Listing Information:')").invoke("hide");
});

Solution

  • Just assign it to a variable.

    var listings;
    Event.observe(window, "load", function(){
        listings = $$("li:contains('Full Listing Information:')");
        listings.invoke("hide");
    });