AngularJS supports addClass, removeClass jQuery functionality. Here in below examples we can see how to add a class to an element.
AngularJS is providing ng-class to manipulate classes of elements
Angular2 : If you are looking for Angular2 solution, please click here
AngularJS is providing ng-class to manipulate classes of elements
Angular2 : If you are looking for Angular2 solution, please click here
Steps to add class using ng-class :
- Initiate $scope.myClass to array
- Push classes into above array
$scope.myClass = []; $scope.myClass.push('red');
Steps to remove class using ng-class :
- Initiate $scope.myClass to array
- Pop classes from above array
$scope.myClass = []; $scope.myClass.pop('red');
Steps to check class using ng-class :
- Initiate $scope.myClass to array
- Check index of the class that you want to check
$scope.myClass = ['red']; if($scope.myClass.indexOf('red') == -1) { alert('false'); } else { alert('true'); }
Steps to add class using ng-class with JSON
- Initiate $scope.myClass to JSON object of classes and boolean values
- Assign true for the JSON class name, that you want to add
$scope.myClass = {red:false}; $scope.addClass = function() { $scope.myClass.red = true; }Try It Your Self
Steps to remove class using ng-class with JSON
- Initiate $scope.myClass to JSON object of classes and boolean values
- Assign false for the JSON class name, that you want to remove
$scope.myClass = {red:false}; $scope.removeClass = function() { $scope.myClass.red = false; }Try It Your Self
Steps to toggle class using ng-class with JSON
- Initiate $scope.myClass to JSON object of classes and boolean values
- Assign opposite boolean value to the JSON class name
$scope.myClass = {red:false}; $scope.toggleClass = function() { $scope.myClass.red = !$scope.myClass.red; };Try It Your Self
Steps to add class to an elemnt :
- Get angular element of html element
- Use .addClass() method to add class to that angular element
var myEl = angular.element( document.querySelector( '#divID' ) ); myEl.addClass('red');
Steps to remove class from an element :
- Get angular element
- Use .removeClass() method to remove class from that angular element
var myEl = angular.element( document.querySelector( '#divID' ) ); myEl.removeClass('red');
Try It Your Self
Steps to toggle class to an element :
- Get angular element
- Use .toggleClass() method to toggle class to that angular element
var myEl = angular.element( document.querySelector( '#divID' ) ); myEl.toggleClass('red');
Find whether element has particular Class
- Get angular element
- Use .hasClass() method to find whether element has class or not
var myEl = angular.element( document.querySelector( '#divID' ) ); if(myEl.hasClass('red')) { alert('has class red'); }
thanks for this post I was looking since many days
ReplyDeleteGreat Article
DeleteCloud Computing Projects
Networking Projects
Final Year Projects for CSE
JavaScript Training in Chennai
JavaScript Training in Chennai
The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training
Thanks! It was quick help.
ReplyDeleteThis was a nice short & to-the-point post. Thank you mucho!
ReplyDeletethanks .. Remove class code snippet really helped me.
ReplyDeletethanks .. Remove class code snippet really helped me.
ReplyDeleteIs great and thanks, but all these should be done in a directive
ReplyDeleteSuppose I have 3 spans in one div, and two of them has already added class 'red'. Then How can i remove those classes from those 2 spans in angular?
ReplyDeletevar jsEl = document.querySelectorAll('.red');
Deletefor(var i=0; i< jsEl.length; i++) {
var myEl = angular.element(jsEl[i]);
myEl.removeClass('red');
}
Well Said, you have furnished the right information that will be useful to anyone at all time. Thanks for sharing your Ideas.
ReplyDeleteionic training in chennai
Thank you for sharing this Wonderful information.
ReplyDeleteIonic course | Ionic Training
PLC Training in Chennai | PLC Training Institute in Chennai | PLC Training Center in Chennai | PLC SCADA Training in Chennai | PLC SCADA DCS Training in Chennai | Best PLC Training in Chennai | Best PLC Training Institute in Chennai | PLC Training Centre in Chennai | Embedded System Training in Chennai | Embedded Training in Chennai | VLSI Training in Chennai | VLSI Training Institute in Chennai
ReplyDeletePLC Training in Chennai | PLC Training Institute in Chennai | PLC Training Center in Chennai | PLC SCADA Training in Chennai | PLC SCADA DCS Training in Chennai | Best PLC Training in Chennai | Best PLC Training Institute in Chennai | PLC Training Centre in Chennai | PLC SCADA Training in Chennai | Automation Training Institute in Chennai | PLC Training in Kerala
ReplyDeleteThank you for your post. This is excellent information. It is amazing and wonderful to visit your site.
ReplyDeleteWeb Design Training
Nice blog! This is really worth reading. I'm glad that I found your post. Looking forward for more posts from you.
ReplyDeleteManual Testing Training in Chennai
Manual Testing Training in Anna Nagar
Oracle Training in Chennai
your article is very good and very helpful. every one can use and know that how Creating Custom Animations for Use in Tableau. if you want to gif covert to image than check it you can easily understand that how to Use GIF Converter to Get Images for Marketing
ReplyDeleteคาสิโนออนไลน์ที่น่าเชื่อถือและมีความเป็นมืออาชีพที่สุดในตอนนี้
ReplyDeleteโปรโมชั่นGclub ของทางทีมงานตอนนี้แจกฟรีโบนัส 50%
เพียงแค่คุณสมัคร สล็อตออนไลน์ กับทางทีมงานของเราเพียงเท่านั้น
ร่วมมาเป็นส่วนหนึ่งกับเว็บไซต์คาสิโนออนไลน์ของเราได้เลยค่ะ
สมัครสล็อตออนไลน์ >>> Goldenslot
สนใจร่วมสนุกกับ คาสิโนออนไลน์ คลิ๊กได้เลย
มีทั้งคาสิโนออนไลน์ หวยออนไลน์ ฟุตบอลออนไลน์ สล็อตออนไลน์ และอื่นๆอีกมากมาย
Surpassing Article, This post contains great information about this topic. Can you please do a more extra post like from this blog and Thank you much more for sharing this useful info.
ReplyDeletePrimavera Training in Chennai
Primavera Coaching in Chennai
Corporate Training in Chennai
Pega Training in Chennai
Embedded System Course Chennai
Linux Training in Chennai
Job Openings in Chennai
Social Media Marketing Courses in Chennai
Soft Skills Training in Chennai
JMeter Training in Chennai
Primavera Training in Anna Nagar
I have to agree with everything in this post. Thanks for the useful sharing information.
ReplyDeleteselenium Training in anna nagar
selenium Training in Chennai
selenium Training in OMR
java training in T nagar
Salesforce Training in T Nagar
selenium Training in T Nagar
Python Training in anna nagar
IELTS Coaching in OMR
ReplyDeleteThanks for sharing this post. It is very helpful for me to develop my skills in a right way.
Ethical Hacking Course in Velachery
Ethical Hacking Course in T Nagar
Ethical Hacking Course in Tambaram
Ethical Hacking Course in Anna Nagar
Ethical Hacking Course in Porur
Ethical Hacking Course in Vadapalani
Ethical Hacking Course in Thiruvanmiyur
Ethical Hacking Course in Adyar
Ethical Hacking Course in OMR
Thanks for sharing a worthy information. This is really helpful. Keep doing more.
ReplyDeleteSpoken English Classes in Chennai
Spoken English Class in Chennai
Spoken English in Chennai
IELTS Training in Chennai
IELTS Chennai
Best English Speaking Classes in Mumbai
Spoken English Classes in Mumbai
IELTS Mumbai
IELTS Coaching in Anna Nagar
Spoken English Class in T Nagar
Really wonderful blog! Thanks for taking your valuable time to share this with us. Keep us updated with more such blogs.
ReplyDeleteAWS Training in Chennai
AWS Training
AWS Training institute in Chennai
DevOps Training in Chennai
Azure Training in Chennai
VMware Training in Chennai
AWS Training in Velachery
AWS Training in Tambaram
AWS Training in Tnagar
AWS Training in Anna nagar
Awesome post. I am a normal visitor of your blog and appreciate you taking the time to maintain the excellent site. I’ll be a frequent visitor for a long time.
ReplyDeleteACP Sheet
ACP Sheet Price
Aluminium Composite Panel
Are you looking for the best quality F 100 Classic Ford Truck Parts online? Carolina Classics is the manufacturer of best F-100 Ford Truck Parts | Buy F 100 classic Ford truck parts online at Carolina Classics.
ReplyDeleteThanks for sharing this information.
ReplyDeleteWant to Buy Step Down Transformer or Are you Curious about What is Step Down Transformer? Read the blog to get your queries resolved before making a purchase.
The article is so informative. This is more helpful for our
ReplyDeleteselenium training in chennai
selenium online courses best selenium online training
selenium testing training
selenium classes
Thanks for sharing.
This is the first & best article to make me satisfied by presenting good content. I feel so happy and delighted.By Learn Digital Marketing Course Training in Chennai it will help to get Digital Marketing Training with Placement Institute in Chennai. If you Learn Social Media Marketing Training with Placement Institute in Chennai, you will get job soon.
ReplyDeleteLearn Best Digital Marketing Course Training in Chennai in professional institute to get reputed job.
Great blog thanks for sharing Take care of all your search engine optimization SEO, graphic design, logo creation, social media marketing and digital branding need at one stop - Adhuntt Media. Customer satisfaction and service is our priority - We tread that fine line between projecting your visions into tangible reality! Why wait when you can begin your digital marketing journey with us right now at Adhuntt Media.
ReplyDeleteweb designing company in chennai
Nice blog thanks for sharing Tidy up your ambience by decorating them with amazing landscape plants in Chennai. Karuna Nursery Gardens is your portal to all the green that the world has to offer. Revolutionize your indoors, garden, terrace or office right now with us.
ReplyDeleterental plants in chennai
Excellent blog thanks for sharing Buy the best beauty parlour products wholesale in Chennai at Pixies Beauty Shop. Thousands of global top-tier brands to choose from and friendly faces all over, we would love to make your Salon journey, one the world recognizes.
ReplyDeletebeauty Shop in Chennai
Do you want to know more about web design agency Sempris or about what web design agencies can do for you? Then don't hesitate to contact us ! We are happy to assist you. An exploratory conversation or a free price estimate are certainly possible. Webdesign
ReplyDeleteSuch A nice post... thanks For Sharing !!Great information for new guy like Hanuman Chalisa Lyrics
ReplyDeleteThanks for sharing wonderful information blog, its such a great info. keep update.
ReplyDeleteIntensive english program
learn english america
english speaking classes
Intensive English language program
spoken english classes
english conversation course
best english programs
Very useful blog thanks for sharing IndPac India the German technology Packaging and sealing machines in India is the leading manufacturer and exporter of Packing Machines in India.
ReplyDeleteThanks for sharing wonderful information blog, its such a great info. keep update.
ReplyDeletespoken english classes
English conversation course
Best english programs
The development of artificial intelligence (AI) has propelled more programming architects, information scientists, and different experts to investigate the plausibility of a vocation in machine learning. Notwithstanding, a few newcomers will in general spotlight a lot on hypothesis and insufficient on commonsense application. machine learning projects for final year In case you will succeed, you have to begin building machine learning projects in the near future.
ReplyDeleteProjects assist you with improving your applied ML skills rapidly while allowing you to investigate an intriguing point. Furthermore, you can include projects into your portfolio, making it simpler to get a vocation, discover cool profession openings, and Final Year Project Centers in Chennai even arrange a more significant compensation.
Data analytics is the study of dissecting crude data so as to make decisions about that data. Data analytics advances and procedures are generally utilized in business ventures to empower associations to settle on progressively Python Training in Chennai educated business choices. In the present worldwide commercial center, it isn't sufficient to assemble data and do the math; you should realize how to apply that data to genuine situations such that will affect conduct. In the program you will initially gain proficiency with the specialized skills, including R and Python dialects most usually utilized in data analytics programming and usage; Python Training in Chennai at that point center around the commonsense application, in view of genuine business issues in a scope of industry segments, for example, wellbeing, promoting and account.
Great information, nice to read your blog. Keep updating.
ReplyDeletepositive effects of social media
applications of artificial intelligence
ai applications
what is php used for in web design
rpa uipath jobs
salesforce interview questions for experienced
Mua vé máy bay tại Aivivu, tham khảo
ReplyDeletevé máy bay đi Mỹ khứ hồi
vé máy bay từ los về việt nam
mua vé máy bay từ anh về việt nam
bay từ pháp về việt nam mấy tiếng