Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery Getting multiple attributes

Is there a way to get multiple attributes in jQuery

 <input type="text" title="hello there" class="maiz"/>


(function() {
  var inputTitle = $("input").attr("title","class");
  console.log(inputTitle[1])//output:undefined
})();

I'm new to jQuery

like image 676
Maizere Pathak.Nepal Avatar asked Mar 21 '26 17:03

Maizere Pathak.Nepal


1 Answers

You can't get multiple attributes, you just have to call attr again:

var input = $("input");
var title = input.attr("title");
var cls   = input.attr("class");

Your example sets the value "class" to the title attribute.

Or more similar to your original code:

var inputTitle = [input.attr("title"), input.attr("class")];
inputTitle[1]; // gives you 'maiz'
like image 152
Dennis Avatar answered Mar 23 '26 07:03

Dennis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!