0
<div class="gridmasonry grid_accomodation select_room">
             <div class="item_grid item2">
                 <div class="panel">
                     <div class="img_preview">
                         <h4 class="price"><span>&euro;20 </span>Night</h4>
                         <img src="~/Images/rooms/standard.jpg" alt="img_preview"  />
                     </div>
                     <div class="clsRoomType"><h4>Standart Room</h4></div>
                 </div>
             </div>
             <div class="item_grid item2">
                 <div class="panel">
                     <div class="img_preview">
                         <h4 class="price"><span>&euro;20 </span>Night</h4>
                         <img src="~/Images/rooms/luxury.jpg" alt="img_preview" />
                     </div>
                     <div class="clsRoomType"><h4>Luxury Room</h4></div>
                 </div>
             </div>
             <div class="item_grid item2">
                 <div class="panel">
                     <div class="img_preview">
                         <h4 class="price"><span>&euro;20 </span>Night</h4>
                         <img src="~/Images/rooms/family.jpg"  alt="img_preview"/>
                     </div>
                     <div class="clsRoomType"><h4>Family Room</h4></div>
                 </div>
             </div>
             <div class="item_grid item2">
                 <div class="panel">
                     <div class="img_preview">
                         <h4 class="price"><span>&euro;20 </span>Night</h4>
                         <img src="~/Images/rooms/vip.jpg"  alt="img_preview"/>
                     </div>
                     <div class="clsRoomType"><h4>VIP Room</h4></div>
                 </div>
             </div>
             <div class="item_grid item2">
                 <div class="panel">
                     <div class="img_preview">
                         <h4 class="price"><span>&euro;20 </span>Night</h4>
                         <img src="~/Images/rooms/deluxe.jpg"  alt="img_preview"/>
                     </div>
                     <div class="clsRoomType"><h4>Deluxe Room</h4></div>
                 </div>
             </div>
             <div class="item_grid item2">
                 <div class="panel">
                     <div class="img_preview">
                         <h4 class="price"><span>&euro;20 </span>Night</h4>
                         <img src="~/Images/rooms/romantic.jpg" alt="img_preview" />
                     </div>
                     <div class="clsRoomType"><h4>Romantic Room</h4></div>
                 </div>
             </div>
         </div>

I have a structure of DIVs as above. I need to get the text of DIV with the class "clsRoomType" on each time when i click on a DIV item with the class "item_grid item2"

I tried the below code, but it shows the text of all items

 $(document).ready(function () {

        $(".item2").click(function () {
            alert($(".item2").find('div.clsRoomType').text());
        });
    });

Current result: Standart Room Luxury Room Family Room VIP Room...

I want each item on each click.

4 Answers 4

3

Replace

alert($(".item2").find('div.clsRoomType').text());

with

alert($(this).find('div.clsRoomType').text());

That will give individual item.

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

3

Try this:

 $(document).ready(function () {
    $(".item2").click(function () {
        alert($(this).find('div.clsRoomType').text());
    });
 });

Comments

1

You have to look for a class in a given element

$(document).ready(function () {

    $(".item2").click(function () {
        alert($(this).find('div.clsRoomType').text());
    });
});

1 Comment

And how is that different.
1

try this

$(document).ready(function () {

$(".item2").click(function () {
    alert($(this).find('div.clsRoomType').text());
});
});

Demo http://jsfiddle.net/mYa9c/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.