public String addClass(String content, String selector, List<String> classNames, int amount) {

		Element body = parseContent(content);
		
		List<Element> elements = body.select(selector);
		if (amount >= 0) {
			// limit to the indicated amount
			elements = elements.subList(0, Math.min(amount, elements.size()));
		}
		
		if (elements.size() > 0) {
			
			for (Element element : elements) {
				for (String className : classNames) {
					element.addClass(className);
				}
			} 
			
			return body.html();
		} else {
			// nothing to update
			return content;
		}
	}
public String addClass ( String content , String selector , List < String > classNames , int amount ) { Element body = parseContent ( content ) ; List < Element > elements = body . select ( selector ) ; if ( amount >= 0 ) { elements = elements . subList ( 0 , Math . min ( amount , elements . size ( ) ) ) ; } if ( elements . size ( ) > 0 ) { for ( Element element : elements ) { for ( String className : classNames ) { element . addClass ( className ) ; } } return body . html ( ) ; } else { return content ; } }
Adds given class names to the elements in HTML.

@param content
HTML content to modify
@param selector
CSS selector for elements to add classes to
@param classNames
Names of classes to add to the selected elements
@param amount
Maximum number of elements to modify
@return HTML content with modified elements. If no elements are found, the original content
is returned.
@since 1.0