0

I have an onclick function for an <ul><li>,
but I need to set a variable from the id of an <a href> tag insde the <li> and I'm not sure how.

I have:

$('#dropdown ul li').click(function(){

var picked = $(this).attr('id'); // this part I don't know.
// var picked = $(this).href('id'); didn't work.

$('picked1').innerHTML = picked ;

 }); 

 /* pulling from a list of items that look like:

 <li id='name_1'><a id="name_a">text1</a></li>
 <li id='name_2'><a id="name_b">text2</a></li>
 <li id='name_3'><a id="name_c">text3</a></li>

 If I clicked 'name_2', (this), i need to set a variable from 'name_b', within it.
 */
3
Contributors
7
Replies
19
Views
4 Years
Discussion Span
Last Post by pixelsoul
0

I'm not entirely sure I understand what you are trying for. What is the variable you need and where do you want to put it?

And can I ask, what are you trying to do? Having one of the navigation items changed when you are on a page?

Edited by pixelsoul

0

hai turpentyne,

i am getting confusion about your requirement

can you clearly explain me about the requirement?

If I clicked 'name_2', (this), i need to set a variable from 'name_b', within it

so that i will try to give a way to solution

happy coding

0

Actually, I found a way around it, with a simpler method to do what I need. But, I'm still curious to konw. So, if I were to boil it down - how do I get the id of elements inside whatever $(this) is.

So, if it's an <li> with php generated id's, and I don't know what those id's are. How do I get the id of an element inside of that clicked <li>. In this case it was an <a> tag.

0

really??? haha! It didn't work for me, so I just naturally assumed I wasn't doing the right thing.

0

The only difference with my example is that the click event is set to the "a", where you have it set to just the li.

Edited by pixelsoul

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.