?
Solved

.next element

Posted on 2014-04-12
1
Medium Priority
?
233 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 82

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

Application Discovery Service in AWS

In the era of the cloud, customers migrating away from their existing on-premise infrastructure. This requires lots of planning, strategies, and effort to identify their existing resources and determine how best to migrate.  Datacenter migrations happen in four phases -

Question has a verified solution.

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
This article discusses how to create an extensible mechanism for linked drop downs.
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

764 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