Solved

.next element

Posted on 2014-04-12
1
224 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 82

Accepted Solution

by:
leakim971 earned 500 total points
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
The viewer will learn how to dynamically set the form action using jQuery.
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now