Solved

jquery .remove div with multiple classes not working

Posted on 2014-02-28
2
1,136 Views
Last Modified: 2014-02-28
Hi all,

I am trying to remove a dynamically created div with classes using jquery. If i add an id to the div the remove works (i.e. .remove('#<ID>'); but when its not removing based on a css class or classes.

Can anyone help please?

function highlightField(textfield, valid) {

            if (textfield.parent().is(".textbox-wrapper")) {
                textfield.parent().remove('.input-status.input-cross'); //not working
                textfield.parent().remove(".error-popup"); //not working either?
                textfield.parent().remove(".valid-popup");
                alert('removed any popups');
                textfield.unwrap();
            }

            textfield.wrap("<div class='textbox-wrapper'></div>");

            if (!valid) {
                textfield.removeClass("valid"); //just in case
                textfield.addClass("error");
                textfield.parent().append("<div class='input-status input-cross'></div>");
            }
            else {
                textfield.removeClass("error"); //just in case
                textfield.addClass("valid");
                textfield.parent().append("<div class='input-status input-tick'></div>");
            }
        }

Open in new window


its a basic method I have for highlighting any fields which are either valid or invalid.
0
Comment
Question by:flynny
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Author Comment

by:flynny
ID: 39894324
if it helps heres the html produced from a call to it

<div class="textbox-wrapper">

    <input id="ctl00_ContentPlaceHolder1_FirstNameTextbox" class="half error" type="text" maxlength="30" name="ctl00$ContentPlaceHolder1$FirstNameTextbox" placeholder="First name"></input>
    <div class="input-status input-cross"></div>

</div>

Open in new window


also if I alert out the html i.e.

<input placeholder="First name" name="ctl00$ContentPlaceHolder1$FirstNameTextbox" maxlength="30" id="ctl00_ContentPlaceHolder1_FirstNameTextbox" class="half error" type="text"><div class="input-status input-cross"></div>

Open in new window


which seems correct i think?
0
 
LVL 57

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 39894437
Try this
	if (textfield.parent().is(".textbox-wrapper")) {
		textfield.parent().find('.input-status.input-cross').remove(); //not working
		textfield.parent().find(".error-popup").remove(); //not working either?
		textfield.parent().find(".valid-popup").remove();
		alert('removed any popups');
		textfield.unwrap();
	}

Open in new window

0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question