RemoveClass not responding to two part form - javascript

I have a form that I am controlling visually with jQuery. I am using removeClass to remove a few classes on the first part of the form, which works fine. However when the button is clicked to go to the second part of the form, the form is not responding to the removeClass and I can't figure out why this is happening. I have tried adding an event (below) to see if I am able to target the class/id within the div, but no luck either. Any suggestions would be greatly appreciated.
$(document).ready(function(){
$('input#createMember').click(function(){
$.find('account-edit-engagement-block').removeClass('col-md-6');
});
});
Ok Here is the code for the form. I am trying to remove the classes associated to this segment ""
<div class="form-container promo-carousel-lp__form">
<h4>Get $150 for signing up</h4>
<div class="account-edit-engagement-block"><script
src="/bundles/ActivationFormBlock?
v=FmZitrV3y_UtI4ysqjWZ2dKUPIGjPegx-dWRIDqgcrI1"></script>
<div id="activateAccount">
<div class="">
<div id="activationview"></div>
<div id="editview">
<script src="/bundles/AccountEdit?
v=V6iouLyL7iEfMRGYC4DTKQc8Yv95VNfdF_08-ZAgeRU1"></script>
<div id="editAccount">
<div class="row">
<div class="col-md-offset-3 col-md-6 col-xs-12">
<form action="/api/UserApi/EditUserAsync"

EDIT Try this again, iterate:
$(document).ready(function(){
$('input#createMember').click(function(){
$('.account-edit-engagement-block').each(function(ix,ex){
$(ex).find('.col-md-6').removeClass('col-md-6');
});
});
});
Fiddle HERE: https://jsfiddle.net/u5bLfrks/1/

Related

Find out which close button closed an alertbox

I have an alert box with multiple close buttons:
<div data-alert class="alert-box cookies-consent">
<div class="informative-text">
Using cookies...
</div>
<div class="close-buttons">
Sure
Opt Out
</div>
</div>
I registered a handler for the close event as the docs suggest:
$(document).on('close.fndtn.alert', function(event) {
console.info('An alert box has been closed!');
console.info(event);
});
But unless I've missed it, the event doesn't seem to indicate which of the buttons was clicked.
How should I modify my HTML/JS to find out which of the close buttons was clicked? I don't want to modify Foundation's own JS, and I do want the UI behavior to remain consistent for both buttons, nice transitions and all.
Here is working spinet as #Panomosh mentioned above:
$('a.close').on('click',function(e){
console.log($(e.target).text())
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div data-alert class="alert-box cookies-consent">
<div class="informative-text">
Using cookies...
</div>
<div class="close-buttons">
Sure
Opt Out
</div>
</div>
Greetings!

HTML div class conditional URL

I Forked an NBA 2K Random Team picker from another user and was tweaking it to my needs. I am stumped on something probably simple for one of you. Thanks in advance.
When the "Randomize" button is clicked, the team "name" and "logo" display. I added a "roster" url to display as well but I want that url to be clickable in to a new tab/window. I can't seem to figure it out.
https://codepen.io/nick-c/pen/dNwMaZ
Below is just the html. I couldn't manage to post all the script and css.
<div class='container'>
<div class='title'>
<img src='http://fluidesign.co.uk/wp content/uploads/2016/12/NBA_2K17_logo.png'/>
</div>
<div class='team home'>
<h3>Home</h3>
<div class='logo'></div>
<div class='name'>?</div>
<div class='roster'>Click for Rosters</div>
<div class='random'>Randomize</div>
</div>
<div class='team away'>
<h3>Away</h3>
<div class='logo'></div>
<div class='name'>?</div>
<div class='random'>Randomize</div>
</div>
<div class='vs'>vs</div>
<div class='clear'></div>
</div>
You didn't "manage to post all the script and css"? Where's the difference in pasting it into a codepen or pasting it into the code snipped tool here on StackOverflow? Anyway...
You are currently just setting the link as a text in the line:
$(".home .roster").text(teams[index].roster);
But what you want to do is add it as a link:
$(".home .roster").html('Webpage URL');
Easy, huh? ;) See a working fork of your codepen here: https://codepen.io/anon/pen/xgmEOm
i think you want this
example

jQuery Remove Closest Issues in Chrome

Noob here sorry. I'm trying to remove an ancestor when my WP loop returns an empty message with a specific class. Firefox is displaying as intended, removing the desired DOM, but Chrome is removing the targeted element and no ancestors.
Basic HTML markup:
<div id="content" class="container site-content">
<div id="primary" class="main-content">
<div id="main-box-1" class="main-box border-top">
<div class="main-box-inside">
<p class="no-modules-msg">No posts match your criteria. Please choose different options.</p>
</div>
</div>
<div id="main-box-2" class="main-box border-top ">
<h3 class="main-box-title">More Stuff</h3>
<div class="main-box-inside">
</div>
</div>
</div>
</div>
And my script:
(function($) {
$("document.body").ready(function() {
$("p.no-modules-msg")
.closest(".main-box")
.remove(".main-box")
})
})(jQuery);
It's working correctly in fiddle, but not on the live site...
https://jsfiddle.net/y90gtt6t/
The reason it's not working on your site, is because the documentation is quite clear, only the document has a ready handler
jQuery(document).ready(function($) {
$("p.no-modules-msg").closest(".main-box").remove()
});
Your use of "document.body" actually looks for an element like <document class="body"></document>, which it hopefully never finds.

jQuery in Meteor having trouble finding DOM selectors

Here is the template whose DOM elements I am trying to control:
<template name='libraryTemplate'>
<div class="container-fluid library_container">
<div class="row">
<div class="col-sm-6">
<h1 id='maglens_library_header'>MY LIBRARY</h1>
<div id='library_page_break'></div>
<div id='folders_text'>
Folders:
</div>
</div>
<div class="col-sm-6">
<a class='button-text btn' id='add_new_button'>ADD NEW</a>
</div>
</div>
<div class="row">
<div class="col-sm-3 folders" id='google_drive_thumbnail'></div>
</div>
</div>
</template>
And here is the jQuery Im using to do so. My $('body') selector works fine, and my log statement just inside $(document).ready() behaves correctly, but why can't I target the selector $('.folders')? Upon inspection of the DOM, I can see exactly where the code is, but it's like jQuery thinks it doesnt exist?
$(document).ready(function(){
console.log('document ready');
$('.folders').on('click', function(){
console.log('folders clicked');
})
// $('body').on('click', function(){
// console.log('body clicked');
// })
});
I don't see any selectors named folders.
I do see <div id='folders_text'>.
That's why your body event fires but your other one doesn't.
Secondly, you should be using template events, you're working with Meteor now.
Template.libraryTemplate.events({
'click .folders': function() { console.log('clicked') }
})
I'd definitely recommend using the meteor events as everyone else suggested.
What you had actually works, it is just since the div with the "folders" class has no content, the div is very small (unless you have a height attribute on ".folders" or "#google_drive_thumbnail") and thus very hard to click on. Inspect element on the div and you'll see the size

jQuery lightbox(featherlight) not working with click event

I am using featherlight lightweight jQuery lightbox plugin but I don't understand how to load lightbox using with click event as I am not good with jQuery codes.
Here is my code work:
HTML:
Load Lightbox
<button id="openbox">Load Lightbox on click event</button>
<div class="lightbox" id="fl1">
<h2>Delete Item</h2>
<div class="row">
<div class="twelve columns">
<strong>Are you Sure?</strong>
<br>blubblub?
</div>
</div>
<div class="right"> Close
Yes
</div>
</div>
jQuery:
jQuery(document).on("click", "#openbox", function() {
jQuery('.lightbox').featherlight();
});
JSFiddle: jsfiddle.net/g68bZ/18/
Comment Reply:
But what If I want to display lightbox with logical condition like:
var checkedCount = $('.chkAssets:checked').length; // Getting some counts
if(checkedCount == 1){
// Load lightbox if condition is match
}
I hoping someone guide me proper way.
Thanks.
$.featherlight('#fl1');
Pay attention that the lightbox has id "fl1"
here is the fiddle
http://jsfiddle.net/g68bZ/26/
and here with if else example
http://jsfiddle.net/g68bZ/27/

Categories

Resources