UI Dev
UI Dev

Reputation: 699

Replace the first header text with jquery

I have headers like

<h3 class="left_header">First job partner</h3>
<h3 class="left_header" style="text-align:center;">Don't have an account ?</h3>

Now i want to replace the first header with Job partner. how to do it by jQuery or Java script.

Upvotes: 3

Views: 853

Answers (7)

Govind Singh
Govind Singh

Reputation: 15490

you can use.first() (http://api.jquery.com/first/)

$( "h3" ).first().html("Job partner");

OR

you can use jQuery( ":first" ) (https://api.jquery.com/first-selector/)

$(".left_header:first").html("Job partner");

fiddle

Upvotes: 2

Ishan Jain
Ishan Jain

Reputation: 8161

Your code :

jQuery(".left_header h3").text("Public offers");

your code didn't match with your requirement. Because above code select all h3 elements under the "left_header" class. And In your HTML h3 have an class left_header. So you should use following selector to select elements-

$("h3.left_header");

Now you want to select only first element, so you can use index number like this -

document.getElementsByClassName("left_header")[0].innerText = "Job Partner";

OR

var g = $("h3.left_header");
$(g[0]).text("Job Partner");

Demo1

Demo 2

Note: There are more than one way exist to accomplish this task-

$(".left_header:first").text("Job Partner");

Working demo 1

Upvotes: 1

Healkiss
Healkiss

Reputation: 367

JQuery :

$('.left_header').first().text("Job Partner");

Upvotes: 2

Jayesh Goyani
Jayesh Goyani

Reputation: 11154

try with this.

$(".left_header:first").html("yourNewTitle");

Upvotes: 2

Dhaval Marthak
Dhaval Marthak

Reputation: 17366

Try this

$("h3:first-child").html("Job Partner")

demo

Upvotes: 2

Milind Anantwar
Milind Anantwar

Reputation: 82231

Try this:

 $('h3:first-child').html('sublink_active');

Working Demo

Upvotes: 2

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

Reputation: 67207

Try to grab the h3 tags with the class .left_header and take the first instance from the element collection using :first selector,

$('h3.left_header:first').text('Job partner')

DEMO

Upvotes: 3

Related Questions