1

I have an asp.net application in which i have this code :

<div class="divpere" >
                                        <div class="divfille1" ><label> Métier</label></div>
                                        <div class="divfille2" >
                                          <input type="text" name="nom" id="Text1"  value="" runat="server" />
                                          <asp:Button ID="addjob" Text="Ajouter" runat ="server"/>
                                        </div>
                                        </div>
                                         <br /> <br />

                                    <h4>Mes métiers</h4>
                                    <br />

                      <div class="widgetcontent bordered">
                            <div class="row-fluid">
                               <div class="span3 profile-left">
                                <ul class="taglist" id="mess" runat="server">
                                    <li><a href="">HTML5 <span class="icon-remove"></span></a></li>
                                    <li><a href="">CSS <span class="icon-remove"></span></a></li>
                                    <li><a href="">PHP <span class="icon-remove"></span></a></li>
                                    <li><a href="">jQuery <span class="icon-remove"></span></a></li>
                                    <li><a href="">Java <span class="icon-remove"></span></a></li>
                                    <li><a href="">GWT <span class="icon-remove"></span></a></li>
                                    <li><a href="">CodeNgniter <span class="icon-remove"></span></a></li>
                                    <li><a href="">Bootstrap <span class="icon-remove"></span></a></li>
                                 </ul>
                      </div></div></div>

and this script :

jQuery(document).ready(function () {
            jQuery('.taglist a').click(function () {
                return false;
            });
            jQuery('.taglist a span').click(function () {
                jQuery(this).parent().remove();
                return false;
            });
            jQuery('#addjob').click(function () {
              //
            });
        });

the result is :

im I'd like to complete the script to add the click event into the bouton which add a new element ul to the list with a title as the input content

  • How can i do that?
  • What is the best way?

Thanks,

1 Answer 1

1

With method append() you can add to your ul a new li element

try this:

jQuery('#addjob').click(function () {
    $('.taglist').append('<li><a href="">' + $('#Text1').val() + '<span class="icon-remove"></span></a></li>');
});

When you add a dynamic element after if you want to fire it you need to change your previous code to this for example:

        jQuery(document).on('click', '.taglist a', function () {
            return false;
        });
        jQuery(document).on('click', '.taglist a span', function () {
            jQuery(this).parent().remove();
            return false;
        });
Sign up to request clarification or add additional context in comments.

4 Comments

it is good idea : i deleted the runat="server" to avoid the postback but i got aways undefined as new value!!!!!
if the value is undefined means that you don't select the right element. @Lamloumi
can you create a jsfiddle? @Lamloumi
nice i deleted all the runat="server", and it works fine.thanks,

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.