Results: 1580
Notes
  • Newest first
  • Oldest first
  • Newest first(All)
  • Oldest first(All)
Load CSS resource only for mobile devices
<link href="css/d1.m.min.css?t=2.9" rel="stylesheet" media="screen and (max-width: 500px)" type="text/css" />
Another way is to use
handheld
on
media
attribute
<link rel="stylesheet" type="text/css" href="mobile.css" media="handheld"/>
PHP's way to load CSS file for
mobile
devices
if(stristr($_SERVER['HTTP_USER_AGENT'], "Mobile")){
    echo '<link rel="stylesheet" href="style-400.css" type="text/css" />';
}
Load CSS resource only for desktop
<link href="css/d1.min.css?t=2.9" rel="stylesheet" media="screen and (min-width: 501px)" type="text/css" />
Another way is to use
screen
on
media
attribute
<link rel="stylesheet" type="text/css" href="screen.css" media="screen"/>
Using PHP
if(!stristr($_SERVER['HTTP_USER_AGENT'], "Mobile")){
    echo '<link rel="stylesheet" href="style.css" type="text/css" />';
}
Note: Remember this always loads the
d1.m.min.css
but activates it only on screens having max width as
500px
by Valeri Tandilashvili
4 years ago
0
CSS
2
moving from jQuery to native JS
Get element (
input[type=text]
,
select
) value jQuery
let value = $("#element_id").val();
JS
let value = document.getElementById('element_id').value;'
Set value
5
to the specified element (
input[type=text]
,
select
) value jQuery
$("#element_id").val(5);
JS
let value = document.getElementById('element_id').value = 5;'
Check if the specified checkbox is checked jQuery
let is_checked = $("#element_id").is(":checked");
JS
let is_checked = document.getElementById('element_id').checked
Get HTML content of the specified element by element id jQuery
let content = $("#element_id").html();
JS
let content = 
 document.getElementById('element_id').innerHTML
Set HTML content to the specified element by element id jQuery
$("#element_id").html('some html');
JS
document.getElementById('element_id').innerHTML = 'some html'
Get attribute
placeholder
value of the element jQuery
$('#element_id').attr('placeholder');
JS
document.getElementById('element_id').getAttribute('placeholder');
Set attribute
placeholder
value to the specified element jQuery
$('#element_id').attr('placeholder', 'new placeholder');
JS
document.getElementById('element_id').placeholder = 'new placeholder';
Toggle class for an element jQuery
$("#element_id").toggle();
JS
document.getElementById('element_id').classList.toggle("hide");
CSS class
.hide {
	display: none !important;
}
Get selected
radio
value jQuery
let result = jQuery('input:radio[name=vote]:checked').val();
JS
let result = document.querySelector('input[name=vote]:checked').value;
Find
i
element inside another element with id
element_id
jQuery
let icon = $("#element_id").find('i');
JS
document.getElementById('element_id').querySelector('i');
Get
data-value
attribute of
datalist
element using selected text (datalist option's
value
attribute) jQuery
$('#datalist_id [value="selected text"]').data('value');
JS
document.querySelector('#datalist_id option[value="selected text"]').getAttribute('data-value')
Toggle two class for an element jQuery
let el = $('#element')
if(el.hasClass('arrow-down')) {
    el.removeClass('arrow-down');
    el.addClass('arrow-up');
} else {
    el.addClass('arrow-down');
    el.removeClass('arrow-up');
}
JS
let el = document.getElementById('element')
if (el.classList.contains('arrow-up')) {
    el.classList.remove('arrow-up');
    el.classList.add('arrow-down');
} else {
    el.classList.add('arrow-up');
    el.classList.remove('arrow-down');
}
Ajax request jQuery
$.ajax({
    url:'demo_get.asp',
    success:function(sms){
        $('#demo').html(sms);                        
    }
});
JS
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
        document.getElementById("demo").innerHTML = this.responseText;
    }
};
xhttp.open("GET", "demo_get.asp", true);
xhttp.send();
MouseOver event jQuery
$('#element').on('mouseover', function(){
    console.log('mouse over');
});
JS
document.getElementById('element').addEventListener('mouseover', function(){
    console.log('mouse over');
});
Scroll animation down to the specified element's position in 500 ms jQuery
$('html, body').animate({scrollTop:($('#element').position().top)}, 400);
JS
function scrollDownToElement(el) {

    // Milliseconds per move 
    let pm = 50;

    // Padding from top
    let mft = 150;

    // Total animation milliseconds
    let scroll_ms = 500;

    // Calculates target element top position
    let bd_pos = document.body.getBoundingClientRect();
    let el_pos = document.getElementById(el).getBoundingClientRect();
    let height = el_pos.top-bd_pos.top-mft;

    // Calculates per move px
    let spm = height / (scroll_ms / pm);

    // The animation counter to stop
    let spmc = 1;
    let scroll_timer = setInterval(function() {

        // Moves down by {spm} px
        window.scrollBy(0, spm);
        spmc++;

        // Stops the animation after enough iterations
        if (spmc > (scroll_ms / pm)) {
            clearInterval(scroll_timer);
        }
    }, pm);
}
scrollDownToElement('element');
by Valeri Tandilashvili
4 years ago
0
JavaScript
jQuery
2
MySQL provides you with the DELETE JOIN statement that allows you to remove duplicate rows quickly. The following statement deletes duplicate rows and keeps the highest id:
DELETE t1 FROM table_name t1
INNER JOIN table_name t2 
WHERE 
    t1.id < t2.id AND 
    t1.email = t2.email;
by გიორგი უზნაძე
4 years ago
0
MySQL
Duplicate
2
ajax request with callback function using native JavaScript
The function sends ajax request with
vanilla JavaScript
and calls the
callback function
if the third parameter's type is
function
function ajax(url, methodType, callback){
    var xhr = new XMLHttpRequest();
    xhr.open(methodType, url, true);
    xhr.send();
    xhr.onreadystatechange = function(){
        if (xhr.readyState === 4 && xhr.status === 200){
            if (typeof callback === "function") {
                callback(xhr.responseText);
            }
        }
    }
}
Example of calling the above method
ajax(url, 'GET', function(resp) {
    console.log(resp);
})
by Valeri Tandilashvili
4 years ago
0
JavaScript
ajax
2
user and role relationship caused problem with Spatie package
The relationship caused problems We should not write this many to many relationship inside User's model if we use Spatie permissions package
public function roles()
{
    return $this->belongsToMany(Role::class, 'model_has_roles', 'model_id', 'role_id');
}
by Valeri Tandilashvili
4 years ago
0
Laravel
2
When trying to pull the latest commits, the error was
error: The following untracked working tree files would be overwritten by merge:
        app/Log.php
The solution that fixed the problem:
git add * 
git stash
git pull
by Valeri Tandilashvili
4 years ago
0
Git
errors
2
live-sass-compiler
extension can generate either
compressed
or
expanded
version of
.css
files. Configuration for
expanded
version:
"liveSassCompile.settings.formats": [
    {
        "format": "expanded",
        "extensionName": ".css",
        "savePath": "/css/"
    }
]
Configuration for
compressed
version:
"liveSassCompile.settings.formats": [
    {
        "format": "compressed",
        "extensionName": ".min.css",
        "savePath": "/dist/css/"
    }
]
by Valeri Tandilashvili
4 years ago
0
Sass
2
CREATE keyword
Using
CREATE
`keyword we can create different database objects. Creates database
university
CREATE DATABASE university
Creates table:
CREATE TABLE students (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    first_name VARCHAR(100) NOT NULL,
    last_name VARCHAR(100) NOT NULL,
    email VARCHAR(50)
)
Creates database
user1
which will have password
some-pass
CREATE USER 'user1'@'localhost' IDENTIFIED BY 'some-pass';
by Valeri Tandilashvili
4 years ago
0
MySQL
2
Javascript "inArray" alternative for php "in_array" function
returns
true
if
needle
is found inside
 haystack
inArray('find_me', ['text1', 'text2', 'find_me', 'text3']);
returns true
function inArray(needle, haystack) {
  var length = haystack.length;
  for(var i = 0; i < length; i++) {
      if(haystack[i] === needle) { return true };
  }
  return false;
}
by გიორგი უზნაძე
4 years ago
0
JavaScript
PHP Alternatives
2
MySQL JOIN Types
SELECT from two tables
SELECT * FROM Table1;
SELECT * FROM Table2;
INNER JOIN
SELECT *
 FROM Table1 t1
INNER JOIN Table2 t2
   ON t1.fk = t2.id;
LEFT OUTER JOIN
SELECT *
 FROM Table1 t1
LEFT OUTER JOIN Table2 t2
 ON t1.fk = t2.id;
RIGHT OUTER JOIN
SELECT *
 FROM Table1 t1
RIGHT OUTER JOIN Table2 t2
 ON t1.fk = t2.id;
SEMI JOIN – Similar to INNER JOIN, with less duplication.
SELECT *
FROM Table1 t1
WHERE EXISTS (SELECT 1
               FROM Table2 t2
               WHERE t1.fk = t2.id
            );
ANTI SEMI JOIN
SELECT *
FROM Table1 t1
WHERE NOT EXISTS (SELECT 1  
                   FROM Table2 t2
                   WHERE t1.fk = t2.id
                );
LEFT OUTER JOIN with exclusion
SELECT *
 FROM Table1 t1
LEFT OUTER JOIN Table2 t2
  ON t1.fk = t2.id
WHERE t2.id is null;
RIGHT OUTER JOIN with exclusion
SELECT *
 FROM Table1 t1
RIGHT OUTER JOIN Table2 t2
  ON t1.fk = t2.id
WHERE t1.fk is null;
FULL OUTER JOIN
SELECT * FROM Table1 t1
 LEFT OUTER JOIN Table2 t2
  ON t1.fk = t2.id
UNION
SELECT * FROM Table1 t1
 RIGHT OUTER JOIN Table2 t2
  ON t1.fk = t2.id;
FULL OUTER JOIN with exclusion
SELECT * FROM Table1 t1
 LEFT OUTER JOIN Table2 t2
  ON t1.fk = t2.id
 WHERE t2.id IS NOT NULL
UNION
SELECT * FROM Table1 t1
 RIGHT OUTER JOIN Table2 t2
  ON t1.fk = t2.id
 WHERE t1.ID IS NOT NULL;
Two INNER JOINs
SELECT *
 FROM Table1 t1
INNER JOIN Table2 t2
  ON t1.fk = t2.id
INNER JOIN Table3 t3
  ON t1.fk_table3 = t3.id;
Two LEFT OUTER JOINS
SELECT *
 FROM Table1 t1
LEFT OUTER JOIN Table2 t2
  ON t1.fk = t2.id
LEFT OUTER JOIN Table3 t3
  ON t1.fk_table3 = t3.id;
INNER JOIN and a LEFT OUTER JOIN
SELECT *
 FROM Table1 t1
INNER JOIN Table2 t2
  ON t1.fk = t2.id
LEFT OUTER JOIN Table3 t3
  ON t1.fk_table3 = t3.id;
by გიორგი ბაკაშვილი
4 years ago
0
MySQL
JOIN
2
Results: 1580