jQuery – set option by value
$('.selDiv option[value="SEL1"]').prop('selected', true)
source: https://stackoverflow.com/questions/314636/how-do-you-select-a-particular-option-in-a-select-element-in-jquery
$('.selDiv option[value="SEL1"]').prop('selected', true)
source: https://stackoverflow.com/questions/314636/how-do-you-select-a-particular-option-in-a-select-element-in-jquery
var date_diff_indays = function(date1, date2) {
dt1 = new Date(date1);
dt2 = new Date(date2);
return Math.floor((Date.UTC(dt2.getFullYear(), dt2.getMonth(), dt2.getDate()) - Date.UTC(dt1.getFullYear(), dt1.getMonth(), dt1.getDate()) ) /(1000 * 60 * 60 * 24));
}
SOURCE: https://www.w3resource.com/javascript-exercises/javascript-date-exercise-8.php
$("#element_1").replaceWith("<div id="element_2">123<div>");
element = $("input:radio.someClass:checked");
value = $("input:radio.someClass:checked").val();
<div>This is a test</div>
<div><span>Another Div</span></div>
$('div:contains("Another")').css('background-color', 'red');
Get option with attribute data-lang=’en’:
var $myDDL = $('#dropDownList');
var $mySelectedOption = $('option[data-lang="en"]',$myDDL);
get value and text:
var myValue = $mySelectedOption.val(); var myText = $mySelectedOption.text();
var $myDDL = $('#dropDownList');
var myValue = $('option:selected', $myDDL).val();
var myText = $('option:selected', $myDDL).text();
Problem:
var x = 123;
Zanima nas length varijable x.
Rješenje:
var x = 123;
x.toString().length;
Rješenje:
$("#lista option:selected").text();