jquery - Select element by id name ending on OpenLayers -
i trying select element id on openlayers map. have checked element id "openlares_map_4_openlayers_container" number changes (4 8 or 10). trying select element jquery selector finds element ends (see link).
but doesn't seem work. , example can seen in jsfiddle following javascript code:
// osm var osmlayer = new openlayers.layer.osm("osm map"); // map var map = new openlayers.map('mapdiv', { layers: [osmlayer], center: new openlayers.lonlat(0, 0), zoom: 0 }); // elements var = document.getelementsbytagname("*"); (var i=0, max=all.length; < max; i++) { console.log('document.elements: ' + + ' -> ' + all[i].id) } // select elements var mapcontainer = document.getelementbyid("openlayers_map_4_openlayers_container"); $("#tag1").text(" -> "+mapcontainer); console.log('mapcontainer: ' + mapcontainer); var id_ol_container = $("div[id$='_openlayers_container']"); // http://api.jquery.com/attribute-ends-with-selector/ $("#tag2").text(" -> "+id_ol_container); console.log('id_ol_container: ' + id_ol_container);
does know it's wrong jquery?
important lesson: read api documentation before diving deep hacking. whole parsing logic can replaced with:
console.log('id_ol_container: ' + map.layercontainerdiv.id);
here's working jsfiddle demonstrates in action
another important question why think need id of element. not depending on element id names you'd make code more clean , reliable. openlayers code should not mixed dom level code allow independently evolving both.
Comments
Post a Comment