0

I am using a chunk of jQuery code that returns a selected option from a group of image icons. It is integrated into the WordPress WYSIWYG Editor.

When I click on the icon this string is sent to the editor:

image="'+ $('.icon-option i.selected').attr('class') +'"

This code returns: fa fa-heart selected

From this string I want to remove the string selected so that it just reads fa fa-heart.

I tried: image="'+ $('.icon-option i.selected').attr('class').split(' ')[0] +'" but it cut the string off at fa

Is this an easy fix that can be added on to my original jQuery String manipulation call?

2 Answers 2

2

No need for string manip, use the removeClass method:

$('.icon-option i.selected').removeClass("selected");

If you then also need the string of the class names you can expand to:

$('.icon-option i.selected').removeClass("selected").attr("class");
Sign up to request clarification or add additional context in comments.

Comments

2

You can accomplish this by doing:

image="'+ $('.icon-option i.selected').attr('class').split(' selected')[0]

1 Comment

Perfect @rkho. Thanks for the very prompt response. Works perfectly. I thought I was close.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.