RIRedinPA Posted June 7, 2010 Share Posted June 7, 2010 I'm trying to just toggle a couple of objects between hide and show based on their current state but I keep running into the same error message, whether I try $(item).css('display') or $(item).is(':hidden'), I keep getting the (item).x is not a function... (where item is a variable, not a string), however I get the same error message when I hard code a string in there. Here's the relevant jquery code //...code above... $('.clickme').click(function() { //make an array of class names var myClasses = this.className.split(" "); //get last class name var showThis = "#" + myClasses[myClasses.length-1]; //toggle if ((showThis).is(':hidden')) { $(showThis).slideDown(); } else { $(showThis).slideUp(); } }); relevant html stuff <div id="resultsbox"> <ul> <li class="tablerow_1"> <p class="designator shop"> </p> <p class="itemname clickme fileinfo_1" onmouseover="cursorIn();" onmouseout="cursorOut();">GI_Item0003</p> <p class="priority"> <?php for ($s=0; $s<3; $s++) { print "<img src=\"images/star.png\" width=\"10\">"; } ?> </p> <p class="beauty"><img src="images/checkmark.png"></p> <p class="product"><img src="images/checkmark.png"></p> <p class="active"><input type="checkbox" name="id_active"></p> <p class="complete"><input type="checkbox" name="id_complete"></p> <p class="artpending"><img src="images/checkmark.png"></p> <p class="description">Words words words words words</p> <p class="swatch">No</p> <p class="livedate">06/01/2010</p> <p class="status"> <select name="status"> <option value="production">Production</option> <option value="admin">In Admin</option> <option value="live">Live</option> <option value="hold">On Hold</option> </select> </p> <p class="designer">Amy</p> </li> <li> <p class="hideme" id="fileinfo_1">This is where the file path will go</p> </li> The code will return fileinfo_1 for the class to show, but it goes no further than that. I'm assuming jquery is not recognizing the object but why? Thanks Quote Link to comment Share on other sites More sharing options...
Adam Posted June 8, 2010 Share Posted June 8, 2010 I'm failing to spot how that jQuery is related to that block of HTML? I see no elements with a class of "clickme". Quote Link to comment Share on other sites More sharing options...
Adam Posted June 8, 2010 Share Posted June 8, 2010 Sorry, spotted it now. Have you tried alerting the value of "showThis" just before the IF condition to ensure it's what you expect? Quote Link to comment Share on other sites More sharing options...
RIRedinPA Posted June 8, 2010 Author Share Posted June 8, 2010 Sorry, spotted it now. Have you tried alerting the value of "showThis" just before the IF condition to ensure it's what you expect? Yes, showThis comes back as "fileinfo_1" and so, in theory, when concactenated as "#" + showThis should be read as "#fileinfo_1" and point to the correct <p> which is hidden...right? Could it be because I have a class and id in the target <p> that is causing the error? (I actually don't think so but am frustrated at this point and just throwing crap against a wall to see if anything sticks) : D Quote Link to comment Share on other sites More sharing options...
Adam Posted June 8, 2010 Share Posted June 8, 2010 Wait up.. if ((showThis).is(':hidden')) { Don't you mean..? if ($(showThis).is(':hidden')) { Quote Link to comment Share on other sites More sharing options...
RIRedinPA Posted June 8, 2010 Author Share Posted June 8, 2010 Wait up.. if ((showThis).is(':hidden')) { Don't you mean..? if ($(showThis).is(':hidden')) { nice catch and as I go to test it...the server crashes...have to wait till 9 when the help desk guys get here... Quote Link to comment Share on other sites More sharing options...
RIRedinPA Posted June 8, 2010 Author Share Posted June 8, 2010 Wait up.. if ((showThis).is(':hidden')) { Don't you mean..? if ($(showThis).is(':hidden')) { Excellent...you win! Thanks man. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.