Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

JQuery Function

Featured Replies

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 by Renaissance-Design
Please use the code button or tags to format your code.

  • 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 by Renaissance-Design
Please use the code button or tags to format your code.

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 by Pete Prosper

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.