Add element content that contains the data-layer "element" in the tag

Asked

Viewed 28 times

-1

I have the following code:

<ul class="dropdown-list-autocomplete" id="Layer_1abc" data-layer="Layer_1"></ul>

And this JS:

function AtivaAutoComplete(id_mapa, regiao, path_map){

$("ul#dropdown-list-autocomplete[data-layer='"+id_mapa+"']").append('<li>'+regiao+'</li>');

}

What I want to do is: The tag that contains the element data-layer with the value Layer_1 or Layer_2, etc.. You will receive the value of append(), but it’s not working. It only works when I say which #ID is.

1 answer

0


His element has a class dropdown-list-autocomplete and a id Layer_1abc, and, in your code, you’re looking for id dropdown-list-autocomplete.

If you change your selector to:

$("ul.dropdown-list-autocomplete[data-layer='Layer_1']")

or

$("ul#Layer_1abc[data-layer='Layer_1']")

he will find his object.

Code working here: https://jsfiddle.net/mrlew/rqLqza9b/

  • Thanks buddy, lack of attention even rsrs.

  • @Alissonacioli of nothing! Good luck with the project!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.