JQuery - ID not defined. Using a dynamic ID in a function? -


I'm having trouble getting a script to work within the CMS This is a relatively simple jQuery show / hide Which was working properly until I need to use it on a page many times. I tried to change it to use every individual ID of DIV, but now it gives an error in the firebug which

the ID is not defined.

jQuery $ ('article article') $ ('article slide'). Each (function () {var current = $ (this); current.atr ("box_h", current.high ()); $ (".syslides"). Css ("height", "250px"); $ (". ShowHide") .HTML ('& lt; a href = "#" & gt; more & lt; / a & gt;'); $ (". Show" .attr ("href", "javascript: Click (void (0) "$" (". ShowHide a") (function () {openSlider ()})}; function openSlider () {var open_height = $ ("# articleSlide_" + id) .attr ( "(" Box_h ") +" px "; $ (" #SloseSlide_ "+ ID). Estimate ({" height ": open_height}, {duration:" slow "}); $ (" showhide "). Html (' Lt; a href = "#" & gt; more & lt; / a & gt; '); $ ("show.") Click (function () {closeSl $ (". ShowHide" (' < / Pre>

HTML

  & lt; div class = "articleSlide" id = "articleslide_1"> <<> & gt; We create brand management and management, video and motion To provide effective solutions for various types of products and applications through graphics, marketing and advertising, digital and editorial, customers Work together. & Lt; / P & gt; & Lt; P & gt; We understand the markets and how we communicate in a multi-platform environment. We work closely with customers to provide effective solutions for various types of products and applications through brand creation and management, video and motion graphics, marketing and advertising. Digital and Editorial. & Lt; / P & gt; & Lt; / Div & gt; & Lt; Div class = "showHide" & gt;   

edit

OK I think I had misunderstood the id bit included in it. I originally wanted He can choose individual ID of each show / hide the div so that it opens only one. This is my current script that works, but if you have more than one page on the page, it opens and closes them all

  $ ("ArticleSlide "). Each (function () {var current = $ (this), current. ATR ("box_h", current.high ()); $ (".syslides"). Css ("height", "250px"); $ ("Show .hide") html ('& lt; a href = "#" & gt; more & lt; / a & gt;'); $ ("ShowHide"). Attr ("href", "javascript : Zero (0) "); $ (" .a. "). Click (function () {openSlider ()})}); Function openSlider () {var open_height = $ (".syslides"). Attr ("box_h") + "px"; $ (".syslides"). Animate ({"height": open_height}, {duration: "slow"}); $ ("ShowHide"). Html ('& lt; a href = "#" & gt; much & lt; / a & gt;'); $ ("Show"). Click (function () {closeSlider ()}} function closeSlider () {$ (". ArticleSlide"). ({"Height": "250px"}, {duration: "slow"}); $ ("ShowHide ") Click Html ('& lt; a href =" # "& gt; more & lt; / a & gt;'); $ (". ShowHide ") (function () {openSlider ()})}   The error is quite clear. You use a variable  id  but never define it.  

Perhaps you For openSlider () the id parameter and your .each handler < Code> $ (this) .attr ('id) to openSlider () . To pass <<> closeSlider () . < For example:

For example:

  $ ('.syslides'). (Function () {var current = $ (this), current.ttr ("box_h" $ (".script"); css ("height", "250px"); $ ("showhide") ATR ("href", "javascript: zero (0)"); $ ("" And "Show one"). Click (function () {openSlider (current.attr ('id'))})}); Function openSlider (id) {var open_height = $ ("# articleSlide_" + id) .attr ("box_h") + "px"; $ ("#SloseSlide_" + ID). Estimate ({"height": open_heit}, {duration: "slow"}); $ ("ShowHide"). Html ('& lt; a href = "#" & gt; much & lt; / a & gt;'); ($ {"(" # $ $ "(" # ArticleSlide_ "+ id) .animate (click on" height ":" 250px "}, (function () {closeSlider (id)}} closeSlider (id) {$ (" # articleSlide_ " $ (""); $ (" Click "Show") (function () {openSlider (id)}}}    

Comments