mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 11:22:45 +00:00 
			
		
		
		
	LibWeb: Handle multiple class names in getElementsByClassName()
The input string is actually a space-separated list of class names, not a single class name.
This commit is contained in:
		
							parent
							
								
									2371446952
								
							
						
					
					
						commit
						df7e64d103
					
				
					 2 changed files with 22 additions and 6 deletions
				
			
		|  | @ -507,10 +507,18 @@ bool Element::is_active() const | |||
|     return document().active_element() == this; | ||||
| } | ||||
| 
 | ||||
| JS::NonnullGCPtr<HTMLCollection> Element::get_elements_by_class_name(FlyString const& class_name) | ||||
| JS::NonnullGCPtr<HTMLCollection> Element::get_elements_by_class_name(FlyString const& class_names) | ||||
| { | ||||
|     return HTMLCollection::create(*this, [class_name, quirks_mode = document().in_quirks_mode()](Element const& element) { | ||||
|         return element.has_class(class_name, quirks_mode ? CaseSensitivity::CaseInsensitive : CaseSensitivity::CaseSensitive); | ||||
|     Vector<FlyString> list_of_class_names; | ||||
|     for (auto& name : class_names.view().split_view(' ')) { | ||||
|         list_of_class_names.append(name); | ||||
|     } | ||||
|     return HTMLCollection::create(*this, [list_of_class_names = move(list_of_class_names), quirks_mode = document().in_quirks_mode()](Element const& element) { | ||||
|         for (auto& name : list_of_class_names) { | ||||
|             if (!element.has_class(name, quirks_mode ? CaseSensitivity::CaseInsensitive : CaseSensitivity::CaseSensitive)) | ||||
|                 return false; | ||||
|         } | ||||
|         return true; | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling