BorysSokolov Posted April 11, 2013 Share Posted April 11, 2013 (edited) I am attempting to assign a class to an element with a specific ID using jQuery. I've done this before without any problems, but for some reason, it's refusing to work now. Here is a series of divs (the code is in a loop) from which I want to retrieve a single, unique div: <div id = "<?php echo $result.'_s'; ?>" > <img src = "http://localhost/gallerySite/users/thumbnails/<?php echo $result; ?>" /> </div> ...and here is the jQuery code I'm doing it with: $('#batman').addClass('myClass'); When I run the program, the class simply isn't being applied to the div, and when I alert the length of the div, it returns 0, even though I can see it in the page source on Chrome. I've checked for spelling errors, and made sure the JS file is included in the correct place. What's odd though, is that when I assign a static value to the divs, let's say, "class = robin", and in jQuery, assign the 'batman' class to the divs with the 'robin', the program works fine. I suspect it may have something to do with the inline PHP in the HTML file, but I'm not sure why that would be an issue. Any ideas? Thanks. Edited April 11, 2013 by BorysSokolov Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 11, 2013 Share Posted April 11, 2013 How could $result._'s' EVER be equal to 'batman'?? Quote Link to comment Share on other sites More sharing options...
trq Posted April 11, 2013 Share Posted April 11, 2013 There is no way this: <?php echo $result.'_s'; ?> will ever produce the string "batman" Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 11, 2013 Share Posted April 11, 2013 Frist!! Quote Link to comment Share on other sites More sharing options...
BorysSokolov Posted April 11, 2013 Author Share Posted April 11, 2013 Uh, yeah, my bad. I changed the names of the variables when I posted. Sorry. $('#batman_s').addClass('myClass'); Quote Link to comment Share on other sites More sharing options...
trq Posted April 11, 2013 Share Posted April 11, 2013 You have provided nothing that is at all helpful I'm sorry. Can we see the markup your php produces? Quote Link to comment Share on other sites More sharing options...
Solution BorysSokolov Posted April 11, 2013 Author Solution Share Posted April 11, 2013 Actually, I just figured it out: The div I've been trying to grab had a dot in its ID. I'll be more careful before posting next time. 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.