Wilson
Wilson

Reputation: 1023

Cant get a form by name with jquery

I'm trying to apply some styles to a div that comes right after a form but, can't get it to work with jquery. I can't set an ID of CLASS to the form because is from a joomla module.

<form action="#" method="get" name="mod_Form"></form>
<div style="text-align: center;"><a href="#" style="font-size: 10px;">Some thing here...</a></div>

This is how I'm trying to do it with jquery:

$(document).ready(function() {
    $("[name=mod_Form]").next('div').css('color', 'green');
});

That code doesn't seem to work...

How can I accomplish my task?

Upvotes: 0

Views: 102

Answers (2)

Ofir Baruch
Ofir Baruch

Reputation: 10356

Your code works.

http://jsfiddle.net/nHtTD/

In order to change the link's color Consider adding find(a):

$("[name=mod_Form]").next('div').find("a").css('color', 'green');​​

EDIT: After reading your comments: (Works for me)

http://jsfiddle.net/nHtTD/1/

Upvotes: 0

Felix Kling
Felix Kling

Reputation: 816462

Link elements don't inherit the text color form their parent. You have to set it explicitly on them:

$("[name=mod_Form]").next('div').find('a').css('color', 'green');

DEMO

If you want to set the color for the links and the content of the div, you can include the div with .andSelf [docs]:

$("[name=mod_Form]").next('div').find('a').andSelf().css('color', 'green');

Upvotes: 2

Related Questions