Tips for updating the css class for multiple DOM elements using jQuery

I am currently attempting to modify the class property of a specific DOM element (in this case, a label tag) using jQuery version 1.10.2.

Here is the code snippet I have written:

var MyNameSpace = MyNameSpace || {};
MyNameSpace.enableDisableLabels = (function() {
  var m_labelIds = {
    "bookId": "book",
    "customerId": "customer"
  };

  var mf_getjQueryDOMObjectReperesentation = function(arrayObjIds) {
    var result = {};
    $.each(arrayObjIds, function(id, value) {
      result[id] = $("#" + value);
    });
    return result;
  };

  var mf_unBoldLabels = function(arrayjQueryObjLabels) {
    $.each(arrayjQueryObjLabels, function(id, value) {
      value.atrr("class", "outputLabelOpt"); // ISSUE: TypeError: value.atrr is not a function
    });
  };

  var arrayjQueryObjLabels = mf_getjQueryDOMObjectReperesentation(m_labelIds);
  mf_unBoldLabels(arrayjQueryObjLabels);

}());
.outputLabelOpt {
  color: #0B63CA;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

<body>
  <label id="book" style="font-weight:bold">book</label>
  <label id="customer" style="font-weight:bold">customer</label>
</body>

However, an error occurs:
TypeError: value.atrr is not a function

Could you please provide guidance on what mistake I am making and how to correct it.
Any assistance would be greatly appreciated.

Thank you in advance,
mismas

Answer №1

Simple mistake: instead of atrr, it should be attr ;-)

Answer №2

Remember, it's value.attr not .atrr.

When it comes to working with the class attribute, don't forget about .addClass("classname") and .removeClass("classname").

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Assigning binary messages a structure similar to JSON for the purpose of easy identification

Is there a way to differentiate binary messages from a server by tagging them with a type attribute? Currently, I am working with node.js and sending binary images as blobs to my client. However, I now also need to send other file types like .txt over the ...

The search results on my website are completely unaffected by jQuery

One website I have allows me to search within the database, focusing on boats at the moment. I have set up this form: <form method="post" action=""> <input type="text" class="form-control" id="searchField" name="searchField" autocomplete="of ...

What steps should I take to resolve the issue with running npm start?

I am encountering an issue while using React and trying to run my application. When I execute "npm run start," I receive the following error message: npm ERR! Missing script: "start" npm ERR! npm ERR! Did you mean one of these? npm ERR! npm star # Mark ...

jQuery droppable: Encounter of an unexpected TypeError: undefined lacks the characteristics of a function

I'm trying to implement drag and drop functionality on my website. However, I am encountering an error message in the console that says: Uncaught TypeError: undefined is not a function ... presentation-categories.js?version=1:23. The error occurs at ...

Utilizing JavaScript regex to remove substrings that contain parentheses

I am working with a string variable named myString that includes some unwanted content towards the end: var myString = 'The sentence is good up to here foo (bar1 bar2)'; var toBeRemoved = 'foo (bar1 bar2)'; I am looking for the best w ...

Challenges with ASP.NET MVC controller actions and jQuery AJAX requests

I've been attempting to pass JsonResult into my jQuery AJAX function using the following code: $.ajax({ contentType: 'application/json, charset=utf-8', type: "POST", url: "/Controller/TestJson", cache: ...

Can you explain the functionality of sinon's stub.yields method?

The explanation given in the documentation for sinon regarding stub.yields is as follows: By using stub.yields([arg1, arg2, ...]), you are essentially performing a function similar to callsArg. This will result in the stub executing the first callback it ...

Limit the selection to just one element in a v-for loop in VueJS

I am utilizing Vue v2 My goal is to change only the properties of the selected element. Specifically, when the response is marked after clicking, it should switch to red color with a text that reads 'Unmark'. Conversely, if the button is clicked ...

Is it just me, or does floating right not seem to work on 404 pages?

I have been working on setting up a unique header and footer design for a client's website. You can check it out here: Everything is looking good with the social media links floating to the right on all pages, except for some reason on the 404 error ...

Trouble with Bootstrap popover functionality

Twitter bootstrap-2.3.2 popover is being utilized in my BackboneJs project. When I click, a function is triggered to open the popover: <li> <a class="candidPopover" href="#" id="loginUser" rel="popover"><%= candidateName %></a> & ...

How exactly does this JavaScript code determine the index of the maximum value within an array?

Examining the specific line of code: let largest = arr.reduce((a,v,i) => v > a[1] ? [i,v] : a, [-1,0]); I find this part a, [-1,0] particularly perplexing, as I am unsure of its syntax. How does a function before the comma? ...

The Express.js server encounters a 404 error, causing it to panic and throw an exception before I can even address the issue

(Just so you know, I'm utilizing the Blizzard.js npm package in combination with Express.) I am currently working on a web application that allows users to search for statistics of specific video game characters (profiles created by players). Given t ...

Type of result from a function that returns a linked promise

In my class, I have a method that returns a chained promise. The first promise's type is angular.IPromise<Foo>, and the second promise resolves with type angular.IPromise<Bar>. I am perplexed as to why the return type of doSomething is an ...

Transform your scene into a stunning 3D texture using THREE.js's 3D Render Targets feature

After exploring the THREE.js example available here, I am curious about how to avoid scenes rendered as textures from appearing 'flattened'. Essentially, I want to maintain the depth illusion within the scene when using a WebGLRenderTarget. I ha ...

"Creating a Miniview Panel on a Fabric Canvas: A Step-by-Step Guide

Is there a way to add a mini view panel to my Fabric Canvas like shown in this image MiniView Panel? I want a panel in the corner of my canvas that displays the entire layout. Similar to the panel on this website . ...

Creating a split-view menu in WinJS: A step-by-step guide

I'm attempting to create a versatile app using JavaScript. I followed a tutorial on the MSDN website, but for some reason, the "nav-commands" class isn't displaying when the splitview is opened. I have set closedDisplayMode = 'none'. & ...

The useEffect hook is triggering multiple unnecessary calls

Imagine a tree-like structure that needs to be expanded to display all checked children. Check out this piece of code below: const { data } = useGetData(); // a custom react-query hook fetching data from an endpoint Now, there's a function that fin ...

What is the best way to store data in a variable in a PHP file and then send it back as a response to an ajax request?

I'm currently working on a project for school where I need to create a database. One issue I've encountered is with receiving a JSON object from PHP. I was able to send data to my PHP file, but I'm having trouble returning it as a response t ...

What is the best method for extracting string values from a JavaScript object?

I am working with JavaScript objects that look like this: {["186,2017"]} My goal is to extract and display only the values: 186, 2017 Initially, I attempted to use JSON.stringify thinking it was a JSON: console.log(JSON.stringify(data)); However, thi ...

The AngularJS price slider may exceed its range if the ng-model is null or below the minimum value

I currently have an rz-slider featured on my webpage that is utilized for gathering the price of a product from the user. In addition to the slider, there are two input fields present which are designated for storing the minimum and maximum values. The ng- ...