4

I have a class suffix named fadecontent in a joomla 3.0 website, and i have to loop trough all div's that have this class suffix using the $.each() function.

I tried this but it seems not to work with class suffixes. joomla docs: class suffix

$('.fadecontent').each(function(i, obj) {

with class suffix i mean this:

<div class="class classSuffix">exemple</div>
<!--example in my code-->
<div class="moduletable fadecontent">content</div>

How to archieve this?

EDIT: the script is in the <HEAD> tag

10
  • Your use of suffix is ambiguous. Do you mean you want to match only part of a class? Otherwise, with the code you provided, $(".fadecontent") should match the elements you're looking for. Commented Aug 26, 2014 at 19:21
  • This question is poorly worded but I think it is a duplicate? stackoverflow.com/questions/2220851/… Commented Aug 26, 2014 at 19:22
  • Did you remember document.ready, including jQuery etc. as what you've got should work fine -> jsfiddle.net/uv20hkry Commented Aug 26, 2014 at 19:22
  • $('.fadecontent') should select <div class="moduletable fadecontent">content</div>. Problem lies elsewhere. May be missing $(document).ready(). Commented Aug 26, 2014 at 19:28
  • @Jojo, from the link you posted it looks like you want to match an actual suffix (in the etymological sense) of a class. filter() into a regex match against this.className. Look around, there probably are lots of material dealing with this problem on the web. Commented Aug 26, 2014 at 19:30

2 Answers 2

3

I'm not sure I understand what you mean by class suffixes. in your example

<div class="moduletable fadecontent">content</div>

That div has both the class moduletable and fadecontent. So this should loop through all the divs with the class fadecontent

$('.fadecontent').each(function() { console.log('Do Something here'); });

If this doesn't achieve what you're looking for, can you post more of your code so we might be able to see any other errors?

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

2 Comments

see update, i added joomla docs class suffix for info. i don't get any errors, just nothing happens.
Ok, it seems like i messed things up while i was testing all these answers. i backed the script up, tested it again and it worked. thank you very much!
0

If you use JQuery's special selectors such as this:

$('[class$="yoursuffix"]')

It should return elements whose classes contain your suffix pattern. You can read more about this here

3 Comments

that doesn't limit it to a suffix. That'll pick up any element with yoursuffix anywhere in the class attribute.
That's the "starts-with" selector, which wouldn't make sense for a suffix. And even if you use the "ends-with" selector, it'll fail if the targeted class is not last in the list of classes.
indeed, this does not work. the suffix is at the end. but sometimes, there are multiple suffixes. still thanks ;)

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.