views:

515

answers:

3

Hello

I am using cufon for some font replacement and jQuery to build a custom accordion.

the code for my accordion is something like this:

 $(".acc-title").click(function () {
   //show something, hide something etc.
 });

Is it possible during the click event to change the color of the replaced (with cufon) font?

something like:

$(".acc-title").click(function () {
       //some something, hide something etc.
       Cufon.replace('how do i select ONLY the title of this', { color: '#fff' });
});
A: 

Not sure but if your cufon is an html element, then you can change color of it this way:

$(".acc-title").click(function () {
  $(".acc-title").css('color', '#ff0000');
});
Sarfraz
it's an h2 tag. h2.acc-title the thing is that probably once the cufon script creates the image replacement it's probably not possible to change it on the fly (like with a click event). 100% not sure of what i'm saying though.
tsiger
i have modified the code as per your comment, plz try it.
Sarfraz
A: 

I would be looking at using a CSS class instead of changing the colour through the css function

$(document).ready(function(){
    $(".acc-title").click(function () {
        $("#cufonid").addClass('cufonCSSClass');
    });
});

Although, if you are looking to show/hide:

        $("#cufonid").show();
        $("#cufonid").hide();

If acc-title is the thing you are operating on, then the following will suffice:

    $(".acc-title").click(function () {
        $(this).addClass('cufonCSSClass');
        //or
        $(this).hide();
        //etc, etc
    });

You could also speed the above acc-title selector by combining it with the ID of a parent element.

    $("#somparentid .acc-title").click(function () {

Or give the item an ID itslef:

    $("#acc-title").click(function () {

Or, your h2 (this is a little slower, though):

    $("h2.acc-title").click(function () {

So, to summarise, your answer might look something like:

$(document).ready(function(){
    $("h2.acc-title").click(function () {
        $(this).addClass('cufonCSSClass');
    });
});

But I'm guessing a bit as I'm not entirely sure what you're after

James Wiseman
it doesn't seem to work. no matter how i reference the item it doesn't change color during an event (click)
tsiger
Check that you selectors are getting something, e.g alert($(yourselector).length); //should be 1 or more
James Wiseman
+1  A: 

You must use Cufon.refresh(); after you change the color by CSS. Like this:

$("#tab1").click(function() {
   $("#tab2").removeClass("selected");
   $("#tab1").addClass("selected");
   Cufon.refresh();
}
Kenneth
Thanks a bunch! That helped me a lot, I always struggled when I needed to change the font color of cufon text dynamically...
Max