this code uses classes as css properties and everything that comes after =
- as the values of it.
ex:
function getProp(classStr) {
return classStr.split('=')[0]
}
function getValues(classStr) {
var values = classStr.split('=')[1]
return values.split(',').join(' ')
}
function transform(el, prop, values) {
$(el).css(prop, values)
}
var elements = $('div, p, span, img, li, ul, a, h1, h2, h3, h4, h5, h6')
elements.each(function(i, el) {
var classList = $(el).attr('class')
if (!classList) return
var classProps = classList.split(' ')
$(classProps).each(function(i, str) {
var prop = getProp(str)
var values = getValues(str)
transform(el, prop, values)
})
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class='color=red font-size=50px font-family=arial'>hello world</div>
soo.. here's a problem. when you want to assign a property with multiple values, like border=2px,solid,black
and if BEFORE it there's a class that doesn't even have the =
sign, the whole code just crashes.
i guess it's because of the
function getValues(classStr) {
var values = classStr.split('=')[1]
return values.split(',').join(' ')
}
function??
how can we check if the property has no values (standart css class) or multiple values that are written with commas (border=2px,solid,black
)?