July 31, 201214 yr Hey all, I'm using this Script to resize a DIV - everything works as it should except it only applies it to the first DIV with that ID (where as I have 10 of them): <script> jQuery(function($) { var screen = window.innerHeight - 200; $('#resize').css("height",screen); }); </script> And the result : <li id="resize" class="item lightbox youtube-video show-titleno-hover" data-id="id-894" style="height: 391px;"> <li id="resize" class="item lightbox youtube-video show-titleno-hover" data-id="id-828"> <li id="resize" class="item lightbox youtube-video show-titleno-hover" data-id="id-177"> <li id="resize" class="item lightbox youtube-video show-titleno-hover" data-id="id-173"> <li id="resize" class="item lightbox youtube-video show-titleno-hover" data-id="id-170"> <li id="resize" class="item lightbox youtube-video show-titleno-hover" data-id="id-164"> <li id="resize" class="item lightbox youtube-video show-titleno-hover" data-id="id-825"> <li id="resize" class="item lightbox youtube-video show-titleno-hover" data-id="id-654"> <li id="resize" class="item lightbox youtube-video show-titleno-hover" data-id="id-815"> <li id="resize" class="item lightbox youtube-video show-titleno-hover" data-id="id-167"> Any ideas how to get this script to apply to all the id="resize" objects? Thanks Tom Edited July 31, 201214 yr by Renaissance-Design Please use the code button or tags to format your code.
July 31, 201214 yr Author Resolved! I found you need to add the ID rather than the CSS class: <script> jQuery(function($) { var screen = window.innerHeight - 200; $('[id=resize]').css("height",screen); }); </script> Edited July 31, 201214 yr by Renaissance-Design Please use the code button or tags to format your code.
July 31, 201214 yr IDs must be unique; you can't have elements with the same ID. Use class="resize" instead. Edit: you posted before me. That may work to get around your issue, but it's still not a good practice to have elements with the same ID. It would work if you had: $(".resize").css("height",screen); Provided you used "resize" as a class instead of an ID Edited July 31, 201214 yr by Pete Prosper
July 31, 201214 yr Like Pete said, ID has to be unique per page, but you can have multiple elements with the same class.
Create an account or sign in to comment