Open selected click of another element with javascript

I was looking for a way to open select / combobox by clicking another item. I read the answers saying this is not possible, but ... How does facebook work?

In your facebook timeline, when you want to change the status date, there is ahchor, and when you click on it, a combo box appears. I thought they applied styles to their choice to make it look like an anchor, but it wasn’t.

Their HTML code has an anchor and a selection element, the latter is hidden. Then I know that the select element is positioned as absolute, but I cannot get from my javascript code how it works.

I tried to simulate this as

$('#element').click(); document.getElementById('element').click(); 

None of this is happening. I saw a script that duplicated the SELECT element, but it added 2 attributes to it: several and size. This changes the look of the selection.

I would like to know how is this possible? I know maybe this will not work in IE <9.

+4
source share
1 answer

Are we talking about this?

 <span class="period periodDay"> <a class="uiIconText periodLabel" style="padding-left: 11px;"><img class="img" src="https://s-static.ak.facebook.com/rsrc.php/v1/yo/r/5-fr6z6ewzf.png" alt="" style="top: 4px;" width="6" height="6" />Tag hinzufügen</a> <select data-name="day" class="periodMenu dayMenu" name="backdated_date[day]"> <option value="">Tag:</option> <option value="1">1</option> <option value="2">2</option> <option value="2">more days...</option> </select> </span> 

The <a> tag is located above the <select> , and the click receives a loop through. If you click the link, the right end will not work.

Update

You can use this trick to open a selection. Place the anchor selected below and move the anchor after clicking.

 <select id="moveme" style="position: relative;" onmousedown="$('#moveme').css('left', '100px');"> <option value="">Tag:</option> <option value="1">1</option> <option value="2">2</option> <option value="2">more days...</option> </select> 

Demo: http://jsfiddle.net/HfFWr/1/

Tested in Firefox, Chrome and IE.

+1
source

Source: https://habr.com/ru/post/1400948/


All Articles