mercredi 21 septembre 2016

Remove span from the DOM using jquery

I'm trying to remove a span element , passing the string tagname in argument of function. , here is my html :

            <div class="col-md-4" id="divtag">
                 <input id="tagi" name="tag" type="text" placeholder="Tags" class="form-control input-md">
                  <?php $tags = $data->get_array_tag($_SESSION['id']);
                          foreach ($tags as $k => $v){
                              echo '<a href="#" onClick= delete_tag("'.$tags[$k][0].'");>'; echo '<span id="'.$tags[$k][0].'" class="label label-default">#'.$tags[$k][0].'</span></a>'. " ";
                                  }
                  ?>

            </div>

When Im doing :

function delete_tag(tag) {
    var del_tag = $(tag);
    console.log(del_tag);
  }

I get my element in the console :

user_account.php:376 [prevObject: n.fn.init[1], context: document, selector: "test"]

I tried this following command but the element is not deleting :

$('span[id^=tag]').remove();

And :

$('span[id^=de_tag]').remove();




Aucun commentaire:

Enregistrer un commentaire