$(".class secondclass").click();

Hi Guys,

Im trying to trigger a jQuery event on the click on one of my buttons. There are multiple buttons on the same page with the same class. Here’s a snippet of the code. Any ideas why this is not working?

HTML:


<input class="view-edit-button view-cv" type="submit" name="view1" title="1022" id="view1" value="View">

jQuery:


$(".view-edit-button view-cv").click(function (e) {
	e.preventDefault();
    var cv_id = $(".view-edit-button view-cv").attr("title");
	// send cv id to script
	// script will then start download
	$.post('downloadcv.php', { id: cv_id },
		function(data)
		{
			if(data != 'error')
			{
				window.location.href = data;
			}
			else
			{
				$('#cv_result').html('<div class="errorbox">CV could not be downloaded.</div>');
			}
	});		
});

You haven’t comma separated your classes, jQuery follows the same concept as CSS where all id’s and classes MUST be comma separated or a parse error occurs. However in JavaScript the case is not the same and not error gets reported to the browser.

$(".view-edit-button, .view-cv").click(function(e) {
    e.preventDefault();
    
    var cv_id = $(this).attr('title');
});

Hi,

Thanks for your help…The jQuery code is now getting triggered, however, its not getting the title attribute value. I think this is because I am using 5 other forms on the page and in the jQuery you listed above you used: var cv_id = $(this).attr(‘title’);

What would I need to change in order for this part to work?

Thanks in advance.

The keyword this referrers to the current element object been the button you clicked on so there is no issue there, to confirm the code is sound i created a jsFiddle which works fine.