Solved

.next element

Posted on 2014-04-12
1
230 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 500 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

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

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…
There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
The viewer will learn how to dynamically set the form action using jQuery.
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)

729 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