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

-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 data-layer element with the value Layer_1 or Layer_2 , etc .. It will get the value of append() , but this is not working. It only works when I say what #ID it is.

    
asked by anonymous 30.01.2017 / 03:00

1 answer

0

Your element has a class dropdown-list-autocomplete and a id Layer_1abc , and in your code you are 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']")

It will find its object.

Code working here: link

    
30.01.2017 / 03:07