Thread View: pl.comp.lang.javascript
1 messages
1 total messages
Started by Tomek
Sun, 20 Jan 2013 20:15
Pytanie o poprawność kodu...
Author: Tomek
Date: Sun, 20 Jan 2013 20:15
Date: Sun, 20 Jan 2013 20:15
28 lines
1952 bytes
1952 bytes
Witam. Założenie: zmiana koloru tła obiektu następnego, po wybraniu wartości
z selecta:
Przykładowo mamy parę selektów, a po nich jakiś obiekt. Jak dynamicznie
pobrać identyfikator obiektu po danym selekcie i zmienić jego tło. Kod
działa, ale czy next w takim przypadku to dobre rozwiązanie? Troche to
naciągane. Dzięki za wszelkie poprawki odnośnie optymalizacji.
$(document).ready(function(){
$("select[id^='sel']").change(function(){
$(this).next("span[id^='szpan']").css('backgroundColor', $(this).val());
});
});
<select id="sel1" style="color: red">
<option value="red" style="color: red"
selected="selected">red</option>
</select>
<span style="padding: 10px; background: red;" id="szpan1"></span>
<select id="sel1" style="color: red">
<option value="red" style="color: red"
selected="selected">red</option>
</select>
<span style="padding: 10px; background: red;" id="szpan1"></span>
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads