<script>
jQuery(document).ready(function ($) {
// Function to check if a cookie exists
function checkCookie(name) {
return document.cookie.split(";").some(function (item) {
return item.trim().indexOf(name + "=") == 0;
});
}
// Check if the cookie exists
if (checkCookie("parent_corner_show_content")) {
// If the cookie exists, hide the section
$("#parent_corner_form_section").hide();
$("#parent_corner_contents_section").show();
}
});
</script>
Category: jQuery
Disable select field with JS/JQuery from another/referrer link
jQuery(document).ready(function($){
$(document).ready(function() {
// Get the dropdown element
var dropdown = $('#input_9_18');
if (document.referrer === 'https://rockymountainpreschool.com/parent-survey/') {
// Prevent click and selection events
dropdown.on('mousedown', function(event) {
event.preventDefault();
});
// Add the "readonly" attribute to the dropdown
dropdown.attr('readonly', 'readonly');
// Add the 'custom-cursor' class to the link
dropdown.addClass('custom-cursor');
}
});
});
jQuery if has class then show
if ($('.client-message')[0]){
$("#message-toaster-close").css("display", "block");
Ajax load page on click
<script>
jQuery(document).ready(function($){
$("#number").on("click", function(){
$.ajax({
url: 'https://gycportal.mysites.io/careers/',
method: 'POST',
data: {
number: '123',
data: 'pankaj'
},
success: function(data) {
console.log(data);
$("#page_details").html(data);
}
});
});
});
</script>
jQuery trigger click
<script>
jQuery(document).ready(function($){
$("#load-content").click(function(){
$(".nav-gyc_dashboard").click();
return false;
});
});
</script>
Jquery simple click funciton
jQuery(document).ready(function($) {
console.log( "ready!" );
$("#dashboard-toggle-menu").click(function() {
console.log("click");
$("#dashboard-toggle-menu").css('display','none');
});
});
Add a class “active” to menu item when clicked.
$(function(){
$('#nav li').on('click', function(){
//$(this).addClass('active').removeClass('off').siblings().addClass('off').removeClass('active'); // no need to add .off
$(this).addClass('active').siblings().removeClass('active');
});
});
jQuery add sticky class on scroll
$(window).scroll(function() {
if ($(this).scrollTop() > 575){
$('.side-banner-sticky').addClass("content_fixed");
}
else{
$('.side-banner-sticky').removeClass("content_fixed");
}
});
jQuery set dynamic image height
jQuery(document).ready(function( $ ){
var heightc = $(".top-ads-banner img").height();
$(".top-ads-banner").height(heightc);
});
CSS
.top-ads-banner {
position: sticky;
top: 0;
-webkit-transition: all 1.5s;
-moz-transition: all 1.5s;
-ms-transition: all 1.5s;
-o-transition: all 1.5s;
transition: all 1.5s;
width: 100%;
margin: 0 auto;
background: #000;
height: 0px;
}
Wrap element by jQuery
jQuery(document).ready(function( $ ){
$("#selector > img").wrap($('<a>',{
href: 'https://yourdomain.com'
}));
});