window.addEventListener('load', function(){
// ваш код
})
document.getElementById('primer2').addEventListener('click', showtext)
<body>
(эти типо расположит весь JS в самом конце содержимого body, без обёртывания в анонимную функцию) <select class="form-control" id="status-scan">
<option value="0">Укажите статус</option>
<option value="1">Выполнено</option>
</select>
$('#status-scan').on('change', function(){
var isDone = $(this).val() == 1;
$('.coolTable tr[data-scan]').each(function(idx, elm){
$(elm).toggle($(elm).attr('data-scan').length > 0 || !isDone);
});
})
<form>
тоже name задал бы я, затестить. [
{
"id": 250,
"name": "Small Batch: Rye IPA",
"tagline": "Rye India Pale Ale.",
"first_brewed": "2016",
"description": "A 7.2% rye IPA loaded with grapefruit notes, pithy citrus, and huge resinous bitterness, with rye character. The Centennial and Columbus flavours are amplified by the spicy, dry rye.",
"image_url": "https://images.punkapi.com/v2/keg.png",
"abv": 7.2,
"ibu": 100,
"target_fg": 1010,
"target_og": 1065,
"ebc": 8,
"srm": 16,
"ph": 4.4,
"attenuation_level": 84,
"volume":
{
"value": 20,
"unit": "litres"
},
"boil_volume":
{
"value": 25,
"unit": "litres"
},
"method":
{
"mash_temp": [
{
"temp":
{
"value": 60,
"unit": "celsius"
},
"duration": 30
},
{
"temp":
{
"value": 65,
"unit": "celsius"
},
"duration": 20
},
{
"temp":
{
"value": 72,
"unit": "celsius"
},
"duration": 15
},
{
"temp":
{
"value": 78,
"unit": "celsius"
},
"duration": 10
}],
"fermentation":
{
"temp":
{
"value": 21,
"unit": "celsius"
}
},
"twist": null
},
"ingredients":
{
"malt": [
{
"name": "Maris Otter",
"amount":
{
"value": 4,
"unit": "kilograms"
}
},
{
"name": "Rye",
"amount":
{
"value": 0.8,
"unit": "kilograms"
}
}],
"hops": [
{
"name": "Centennial",
"amount":
{
"value": 40,
"unit": "grams"
},
"add": "60",
"attribute": "Bitter"
},
{
"name": "Centennial",
"amount":
{
"value": 15,
"unit": "grams"
},
"add": "15",
"attribute": "Bitter"
},
{
"name": "Columbus",
"amount":
{
"value": 15,
"unit": "grams"
},
"add": "15",
"attribute": "Flavour"
},
{
"name": "Centennial",
"amount":
{
"value": 50,
"unit": "grams"
},
"add": "Whirlpool",
"attribute": "Aroma"
},
{
"name": "Columbus",
"amount":
{
"value": 25,
"unit": "grams"
},
"add": "Whirlpool",
"attribute": "Aroma"
},
{
"name": "Columbus",
"amount":
{
"value": 10,
"unit": "grams"
},
"add": "Dry Hop",
"attribute": "Aroma"
},
{
"name": "Citra",
"amount":
{
"value": 10,
"unit": "grams"
},
"add": "Dry Hop",
"attribute": "Aroma"
}],
"yeast": "Wyeast 1272 - American Ale II™"
},
"food_pairing": ["Salmon Fishcakes with Rocket Salad", "Baked Goat's Cheese", "Classic Victoria Sponge"],
"brewers_tips": "Be prepared for a long sparge as the rye content is really high.",
"contributed_by": "John Jenkman <johnjenkman>"
}]
<body>
<script src="index.js"></script>
</body>
const xml = new XMLHttpRequest();
xml.open('GET', 'https://api.punkapi.com/v2/beers/random', true);
xml.send();
xml.onload = () => {
const json = JSON.parse(xml.responseText);
let allItems = '';
json.forEach(item => {
allItems += '<div class="card" style="width: 18rem;"> <img class="card-img-top beer-image" src="' + item.image_url + '" alt="Card image cap" /> <div class="card-body"> <h5 id="nameBeer" class="card-title beer-name">' + item.name + '</h5> <p class="card-text beer-description">' + item.description + '</p> <a href="#" class="btn btn-primary">Go somewhere</a> </div> </div>';
});
document.body.innerHTML = allItems;
};
const all = {
"global": [
{
"id": "1",
"width": "50",
"height": "150"
},
{
"id": "2",
"width": "150",
"height": "350"
},
{
"id": "3",
"width": "750",
"height": "850"
}
]
};
for(item of all.global){
let elm = document.querySelector('.layer' + item.id);
elm.style.width = item.width + 'px';
elm.style.height = item.height + 'px';
}
$.ajax({
method: "POST",
contentType: false,
processData: false,
data: new FormData($(".divAddObject:visible form")[0]),
url: "handlers/add_object.php",
success: function (data){}
});
var formData = $(this).closest('form').serialize();
$.ajax({
method: "POST",
contentType: false,
processData: false,
data: formData,
url: "handlers/add_object.php",
success: function (data){}
});
var obj1 = document.getElementById('test1');
console.log( window.getComputedStyle(obj1, null).getPropertyValue("display") );
<a href="./files/mydoc.pdf" download="lalala.pdf">Скачать</a>
.parent .block:nth-child(2) ~ .block{
display: none
}
.parent.active .block:nth-child(2) ~ .block{
display: block
}
// jQuery
$('.button').on('click', function(){
$('.parent').addClass('active');
});
// или не jQuery
document.querySelector('.button').addEventListener('click', function(){
document.querySelector('.parent').classList.add('active');
});
// я не сумасшедший.
document.querySelectorAll('.str_item[id$="_' + 34 + '"]').forEach(function(item){
console.log(item);
});
$(function(){
$(document).on('click', '.euro, .tenge, .usd', function(e){
e.preventDefault();
var that = $(this);
var dataSelector = 'data-' + $(this).text().toLowerCase();
$('.priceNum').each(function(idx, elm){
$(elm).html($(elm).attr(dataSelector) + ' <div class="cenov">' + that.text() + '</div>')
});
});
})