?
Solved

.next element

Posted on 2014-04-12
1
Medium Priority
?
237 Views
Last Modified: 2014-04-20
I'm trying to figure a way of adding content to the next element after click, so that on click of a button it will find the next matching element and put the results of an ajax response in the matching div, currently Im just going to put some text in.

I thought I could just use:-
$('.menuElemT').click(function () {
    $(this).next('.menuElemL').html('hi-1');
});

Open in new window


So using the html:-
<div class='menuElemT'>Tickets</div>
    <div class='menuElemS'>
        <div class='menuElemL'></div>
        <div class='menuElemR'></div>
    </div>
<div class='menuElemT'>Assetts</div>
    <div class='menuElemS'>
        <div class='menuElemL'></div>
        <div class='menuElemR'></div>
    </div>
<div class='menuElemT'>Reports</div>
    <div class='menuElemS'>
        <div class='menuElemL'></div>
        <div class='menuElemR'></div>
    </div>
</div>

Open in new window


And using the jQuery code:-
$('.menuElemT').click(function () {
    $(this).next('.menuElemL').html('hi-1');
});

Open in new window


By clicking on the div .menuElemT with the content 'Assetts' it should turn it to:-
<div class='menuElemT'>Tickets</div>
    <div class='menuElemS'>
        <div class='menuElemL'>Hi-1</div>
        <div class='menuElemR'></div>
    </div>
<div class='menuElemT'>Assetts</div>
    <div class='menuElemS'>
        <div class='menuElemL'></div>
        <div class='menuElemR'></div>
    </div>
<div class='menuElemT'>Reports</div>
    <div class='menuElemS'>
        <div class='menuElemL'></div>
        <div class='menuElemR'></div>
    </div>
</div>

Open in new window


However when I tie it all together, it doesnt seem to be able to find the element to put 'hi' into:-
http://jsfiddle.net/72DUL/

I dont understand why .next doesnt work.
0
Comment
Question by:tonelm54
1 Comment
 
LVL 83

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 39995964
jQuery.next don't find children, next try to match the NEXT node with the argument no more no less.

Check this : http://jsfiddle.net/72DUL/1/

$('.menuElemT').click(function () {
    $(this).next('.menuElemS').find(".menuElemL").html('hi-1');
});

$('.menuElemL').click(function () {
    $(this).next('.menuElemR').html('hi-2');
});

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question