1

So let's say I have a menu from an array (pmmain) that is generated like this:

$("#pm-page-main") .append("<div class=\"main-box\" id=\"m-box"+b+"\"><div class=\"title-box\"><span class=\"reg-wht-bold\">" + pmmain[b] + "</span></div><div class=\"shadow-box\" id=\"s-box"+b+"\">a</div><BR><BR><img src=\"imgs\\" + pmmain[b] + ".png\"></div>").hide().show(0);}

The m-boxes is where im looking at. Is there a way to get the number of the clicked m-box (eg. There's 16 items in the menu and I clicked on the 2nd one, understandably m-box2 is what i clicked.)? What I want to do is to be able to display another series of menu from that.

Which is like:

$(document) .ready(function(){
$("m-box"?????) .one("click", function(){
$('#arrow-enclosure') .append("<div id=\"highlights-box\"><BR><BR><img src=\"imgs\\"+pmmain[????]+"\"><h1 class=\"line-blank\"><span></span></h1><BR><a href=\"pages\\company name\\company name\\PM\\\">STYLE GUIDE</a> <span>|</span> <a href=\"pages\\company name\\company name\\PM\\Sample Output.pdf\">OLD JOBS PDF</a> <span>|</span> <a href=\"pages\\company name\\company name\\PM\\InDesign Package\">INDD PACKAGE</a> </div>);
});
});

The parts where there's a ????? is the thing that I'm not sure if it's possible to do. Any help would be nice. Thanks!

2

1 Answer 1

1

There's an easy way to get the value of the item clicked, and that's using $(this) in the body of the click handler, like this:

$('.main-box').click(function (){

    // $(this) will give you the jQuery element of whatever was clicked,
    // you can do whatever you like here

    console.log($(this).attr('id'));

});

Check out the jsBin made for this question, where a sample menu is generated that you can click and see the results: http://jsbin.com/pisotefeca/edit?js,console,output

I'm open to any questions!

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

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.