Jump to content

Odd PHP/jQuery Issue


Go to solution Solved by BorysSokolov,

Recommended Posts

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 by BorysSokolov
Link to comment
https://forums.phpfreaks.com/topic/276803-odd-phpjquery-issue/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.