0

I have seen that is it possible to transfer title attribute to class. The question is how to find the elements of the first word (animated) and assign them to the class title?

For example:

<div class="colelem" title="animated infinite bounce"></div>
<div class="colelem" title="animated infinite bounce"></div>

Add the class from the tittle to happen

<div class="colelem animated infinite bounce" title="animated infinite bounce"></div>
<div class="colelem animated infinite bounce" title="animated infinite bounce"></div>
5
  • 1
    I'm not really sure what you're asking, however you can use the addClass() method to add a class to an element Commented Jul 9, 2016 at 9:52
  • 1
    Might $("#u211").addClass($("#u211").attr("title")) do your work Commented Jul 9, 2016 at 9:57
  • One solution. But it is not suitable for mass use. Elements with the animation will be more, and we need to the class of tittle assign them automatically. Commented Jul 9, 2016 at 10:41
  • @НикитаСеверин See jsfiddle.net/vkmw7vb5 Commented Jul 9, 2016 at 10:46
  • Excellent, it works as intended! Commented Jul 9, 2016 at 10:51

1 Answer 1

2

You can use .addClass( function ) to do this work.

$(".colelem").addClass(function(){
    return $(this).attr("title");
});
.animated { 
    color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="colelem" title="animated infinite bounce">A</div>
<div class="colelem" title="animated infinite bounce">B</div>
<div class="colelem" title="animated infinite bounce">C</div>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.