Allow only one checkbox to get selected on a group of checkbox

HTML:

Ham
Egg
Cheese

Javascript:

$(“input:checkbox”).click(function() {
if ($(this).is(“:checked”)) {
var group = “input:checkbox[name='” + $(this).attr(“name”) + “‘]”;
$(group).prop(“checked”, false);
$(this).prop(“checked”, true);
} else {
$(this).prop(“checked”, false);
}
});

 

Advertisements

window.open().focus()

window.open().focus()

Is used to bring the opened window to the top of the current page , even if you click back an parent page an again trying to open the same opened page.

In Firefox window.open() will open the page to top but when you back and forth from previous page it will hide in the background for solving this we can use .focus() to the window open method.

 

wp_nav_menu() with custom html and dynamic class before each menu

This is my Menu Html format :


Code to display Menu in the page dynamically using the above html structure:

$menuParameters = array(
‘theme_location’ => ‘top’,
‘menu’ => ‘Top Menu’,
‘container’ => false,
‘echo’ => false,
‘items_wrap’ => ‘%3$s’,
‘link_before’ => ”,
‘link_after’ => ”,
‘depth’ => 0,
);
$menu = strip_tags(wp_nav_menu($menuParameters ), ‘<a><span>’ );
$find = array(‘<a’);
$replace = array(‘<a class=”list-group-item list-group-item-success” data-parent=”#MainMenu”‘);
echo str_replace( $find, $replace, $menu );

Hook to use dynamic class values before each span element in the menu “nav_menu_link_attributes” :

 

function add_specific_menu_location_atts( $atts, $item, $args ) {
if( $args->theme_location == ‘dashboard’ ) {
print_r($item);
exit;
foreach($item as $key => $value) {

if($key == ‘title’) {

if($value == ‘My Account’)
{
$catIcon = ‘fa-user’;
}else{

$catIcon = ‘fa-file-text’;
}
}
}
foreach($args as $key => $value) {
if($key == ‘link_before’) {
$args->$key = ‘<span class=”fa ‘.$catIcon.’ “></span>’;

}

}
// add the desired attributes:
$atts[‘class’] = ‘btn btn-primary btn-lg’;
}
return $atts;
}
add_filter( ‘nav_menu_link_attributes’, ‘add_specific_menu_location_atts’, 10, 3 );