Solved

jquery .remove div with multiple classes not working

Posted on 2014-02-28
2
1,122 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

742 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