BorysSokolov Posted April 11, 2013 Share Posted April 11, 2013 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. Link to comment https://forums.phpfreaks.com/topic/276803-odd-phpjquery-issue/ 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'?? Link to comment https://forums.phpfreaks.com/topic/276803-odd-phpjquery-issue/#findComment-1424066 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" Link to comment https://forums.phpfreaks.com/topic/276803-odd-phpjquery-issue/#findComment-1424067 Share on other sites More sharing options...
Jessica Posted April 11, 2013 Share Posted April 11, 2013 Frist!! Link to comment https://forums.phpfreaks.com/topic/276803-odd-phpjquery-issue/#findComment-1424068 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'); Link to comment https://forums.phpfreaks.com/topic/276803-odd-phpjquery-issue/#findComment-1424069 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? Link to comment https://forums.phpfreaks.com/topic/276803-odd-phpjquery-issue/#findComment-1424072 Share on other sites More sharing options...
BorysSokolov Posted April 11, 2013 Author 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. Link to comment https://forums.phpfreaks.com/topic/276803-odd-phpjquery-issue/#findComment-1424232 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.