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.

help using Ajax & Jquery to call first class element

Featured Replies

Hi everyone, need some help if u can...

 

im currently designing a website for a hotel. I have a 'special offers' page and im trying to call the latest offer and show it on the home page. The script below is pulling every offer and i cant work out how to only pull the 'first' element.

 

Home page

- http://garracktemp.c....com/index.html

 

Offers page

- http://garracktemp.c...ial-offers.html

 

 

$(document).ready(function(){

$('#test').load('/Garrack_Hotel/special-offers.html .offer_info_content', '', function(response, status, xhr) {

if (status == 'error') {

var msg = "Sorry but there was an error: ";

$(".content").html(msg + xhr.status + " " + xhr.statusText);

}

});

});

 

 

any help with this would be great as im still getting to grips with js and azax

  • Author

i think it may be something along those lines, i did think of a first selector but im not sure where to put it within the script. I'll experiment, thanks for your help.

Edited by James Husband

just viewd the source you need change image src

 

 

<img src="file:///C|/Users/jM/Desktop/Make Believe Media/Projects/img/photos/thumbs/bedroom.jpg" alt="" width="200" height="134">

Edited by ELITE

  • Author

Heres the HTML for the content of the special offers page

 

<div class="offer_info">

<img src="file:///C|/Users/jM/Desktop/Make Believe Media/Projects/img/photos/thumbs/bedroom.jpg" alt="" width="200" height="134">

 

** this is what the script is calling **

<div class="offer_info_content">

<h1>Special Offer</h1>

<p>Details of special offer....</p>

<ul>

<li><a href="#">Book Now</a></li>

</ul>

</div>

</div>

 

** dont want any offer after 1st to be called **

 

<div class="offer_info">

<img src="file:///C|/Users/jM/Desktop/Make Believe Media/Projects/img/photos/thumbs/bedroom.jpg" alt="" width="200" height="134">

 

<div class="offer_info_content">

<h1>Special Offer</h1>

<p>Details of special offer....</p>

<ul>

<li><a href="#">Book Now</a></li>

</ul>

</div>

</div>

Edited by James Husband

here you go sorry for late reply been doing dinner and keeping the baby good

$(document).ready(function(){
$('#test').load('/Garrack_Hotel/special-offers.html .offer_info_content:first', '', function(response, status, xhr) {
if (status == 'error') {
var msg = "Sorry but there was an error: ";
$(".content").html(msg + xhr.status + " " + xhr.statusText);
}
});
});

Edited by ELITE

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.