0

One my designer send some webpage where he used Html(div,Li) CSS for making Drop down list

       <div class="frmcmpstn fl">
            <a class="btn fl cll" href="#">Are you an Hwp/Family Office or an   Institutional <img src="images/dd_arow_ico.png" /></a>
            <ul class="signupdd_dd" style="display:none;">
                <li><a href="#">New Delhi</a></li>
                <li><a href="#">California</a></li>
                <li><a href="#">Gurgaon</a></li>
                <li><a href="#">North East America</a></li>
                <li><a href="#">North America</a></li>
                <li><a href="#">South Africa</a></li>
            </ul>
        </div>

now my problem is I have worked in Asp.net I dont know javascript or JQuery and I know that is possible in java script or JQuery

Can any one tell me how can get selected item (in javascript or JQuery )....?

6
  • Usually, there is no 'selected item' for ul element. So, what do you mean? Commented May 28, 2013 at 9:39
  • What do you want to do with the value? Put it in a JS variable? Send it to the server? Something else? Commented May 28, 2013 at 9:39
  • How do we know if the item is selected?? Commented May 28, 2013 at 9:40
  • There is not ready to use solution here - you need to code it ether on code behind the moment you render that, ether using jquery and come code that compare the current url and change the css on the correct link. Commented May 28, 2013 at 9:42
  • What does Html(div,Li) CSS even mean? Commented May 28, 2013 at 9:42

2 Answers 2

2

I think you mean:

<script type="text/javascript">
    $('.signupdd_dd li').on('click',function(){
        var $selectedLi = $(this);
        //then do some stuff e.g
        $selectedLi.addClass('selected');
    });
</script>
</body> //-> don't add this line but search in your html code this tag and put <script> just before

Or target the tags:

 $('.signupdd_dd li a').on('click',function(){...});
Sign up to request clarification or add additional context in comments.

1 Comment

thanks but how I can use this code ...where I need to add this code ...sorry I dont know JQuery ..so help me please ....thanks
0

Attach an event handler to the click event for each of the anchors a. The event handler will have the element assigned to this which you can use to get the different element properties.

$(".signupdd_dd li a").click(function(e){
    e.preventDefault();
    $(".chosen").removeClass("chosen");
    $(this).addClass("chosen");
    alert($(this).text());
});

You may want to add a class to the a that is clicked for later processing. The event handler should also prevent the default action of the anchors click handler so that navigation does not occur.

Working Example: http://jsfiddle.net/vZkDp/

2 Comments

Hi Kevin ,how I can add event handler or anchore click event please help me ...thanks
Thanks Kevin ...Almost you solved my problem ....but I want to save selected value in database .....So I have to set selected value in c# code .....in code behind .....objMyClass.country = selectedvalue (from screen)

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.