Are you using multiple jQuery statements to add or remove attributes to/from HTML elements? In this post, I’ll share with you, how you can achieve the same in one go.
Recently in one of the projects I was working on, I had to swap attributes between two HTML elements. So I was looking out to see if I could do it in a single statement rather than adding/removing one after the other. Guess what, jQuery has a way do it.
Let us set up the stage first. We shall include <input> elements. The class on the input elements should help you to identify what we’re about to do on that particular element.
Assuming you have jQuery loaded, let us use jQuery to add/remove multiple attributes.
First, let us remove the attributes id and name and then on the second input elemement, we shall add the id and the name attributes.
In order, to remove multiple attributes, use the .removeAttr() method and separate the attributes with a space. And, to add multiple attributes, we must use Plain Object of attribute value pairs in the .attr() method.
You can find the full working demo from JSFiddle.net. I hope you found this tutorial helpful.
2016 was a special year for me and was the year of changes in my life. I shifted my career towards WordPress in 2016.
This is the first time in my life, I’m taking time to sit down and reflect on the course that I traversed over the past 52 weeks. I’m writing this year end review to keep me accountable as I had bid goodbye to my steady job to pursue my interest in developing WordPress and web applications.
I started the year 2016 with a major focus on the following areas.
Attending a tech conference
I launched this blog with a typical Hello World post on January 1, 2016. I have been writing blogs even before 2016, but I was never serious about it.
Starting 2016, I wanted to blog consistently. I had initially planned to write one post per week. Looking at the numbers, I had written only 13 posts all together in the year 2016.
Though I did not hit my mark, I’m happy that I started this blog. By the way, the Hello World post idea was inspired from Sudar’s blog.
Attending A Tech Conference
I have never been to any technical conference before 2016. This was in my to do list for a long time.
Early 2016, I’ve been put up, to work on Oracle PL/SQL project in my full time job and that pushed me to find a conference around the Oracle PL/SQL subject. I assumed that attending a conference could help me speed up my learning process and of course, it did. Eventually, I discovered OTN Yathra, a conference conducted by Oracle ACE folks to share the knowledge on Oracle products. I even wrote a blog post sharing my experiences and takeaways.
Building web applications is something that I enjoy doing and my interest grew multiple times, when I discovered WordPress, a few years ago. Learning to develop WordPress powered websites/applications was very challenging to me at that time. But the desire to do has been lingering within me, since then. So in 2016, I made up my mind to learn WordPress, no matter what.
I soon realized that I can learn WordPress quickly by contributing to open source WordPress projects. I began my contributions by sending the first pull request to the Easy Retweet WordPress plugin.
Later, I contributed to Email Log, a WordPress plugin that logs the emails sent. Sudar, the plugin author was kind to mention about my contributions in his blog.
On the whole, I had spent about 155 hours in 2016 on learning/contributing to open source WordPress projects.
Eventually, these contributions paved my way to land a full time job as a WordPress developer.
In the beginning of 2016, I had planned to travel to at least one destination that I have never been to.
I flew to Goa with my buddies in the month of March. Not only this was my first flight but also it was one of the best trips in my life. On the whole, the trip was totally refreshing, adventurous and exciting.
If you plan to visit Goa, don’t miss out – Parasliding, Parasailing and Water Scooter riding.
Are you unable to login while setting up a development environment from a production site that uses Jetpack’s Single Sign On(SSO)?
I was trying to set up a local (development) site for my personal blog. Since I enabled Jetpack’s SSO, the local site redirected to SSO page and took me to my live blog’s Dashboard page. So, I was looking for a way to disable Jetpack’s SSO.
Here is how to disable Jetpack SSO and login to your local/staging Admin dashboard.
Step 01: Disable the Jetpack plugin
You can rename the Jetpack plugin folder and this will disable the plugin without logging into the Admin dashboard.
Step 02: Access the login page
Once you disable Jetpack plugin, you can access the /wp-login.php (login page) of your local site.